hdoj Problem-1007 A hard puzzle


A hard puzzle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 36871    Accepted Submission(s): 13154


Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
 

Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
 

Output
For each test case, you should output the a^b's last digit number.
 

Sample Input
  
  
7 66 8 800
 

Sample Output
  
  
9 6
 
今天第一次写博客,好激动啊!
这道题就是求a^b的最后一位是什么,懒得用循环求解,就用打表写了这道题;
规律很好总结,很水的题~~~~~~~~~~~
#include<stdio.h>
#include<string.h>
int main()
{
    __int64 l,a,b,len;
    char num[40];
    int u[9][4]={{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}};
    while(scanf("%s%I64d",num,&b)!=EOF)
    {
        len=strlen(num);
        a=num[len-1]-'0';
        if(a==0&&b==0) continue;
        if(b==0) {
            printf("1\n");
            continue;
        }
        switch(a)
        {
            case 1: l=1; break;
            case 2: l=u[1][b%4]; break;
            case 3: l=u[2][b%4]; break;
            case 4: l=u[3][b%2]; break;
            case 5: l=5; break;
            case 6: l=6; break;
            case 7: l=u[6][b%4]; break;
            case 8: l=u[7][b%4]; break;
            case 9: l=u[8][b%2]; break;
            case 0: l=0;
        }
        printf("%I64d\n",l);
    }
    return 0;
}
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值