Hdu1097(计算a的b次幂最后一位数值)

Hdu1097(计算a的b次幂最后一位数值)_第1张图片

 

 1 #include <stdio.h>
 2 #include <math.h> 
 3 int main()
 4 {
 5     int Num1,Num2;
 6     while(scanf("%d %d",&Num1,&Num2)!=EOF)
 7     {
 8         printf("%d\n",getLastNum(Num1,Num2));    
 9     }    
10     return 0;
11 }
12 // 求a的b次幂最后一位数字为什么 
13 int getLastNum(int a, int b)
14 {
15     int n = b%4;
16     int x = a%10;
17     int lastNum = 0;
18     if(n == 0)
19     {
20         lastNum = pow(x,4);
21     }
22     else
23     {
24         lastNum = pow(x,n);
25     }
26     lastNum = lastNum%10; 
27     return lastNum;    
28 } 

 

你可能感兴趣的:(HDU)