Problem 1097

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

#include  < iostream >

using   namespace  std;

int  main()
{
    
int  a, b, result  =   1 , temp, has  =   0 , pos, cap  =   0 ;
    
int  yushu[ 10 ];

    
while  (cin  >>  a  >>  b)
    {
        temp 
=  b;
        has 
=   0 ;
        pos 
=  b;
        cap 
=   0 ;
        
for ( int  i  =   0 ; i  <   10 ; i ++ )
        {
            yushu[i] 
=   0 ;
        }
        
while (a  >   9 )
        {
            a 
%=   10 ;
        }
        
while (temp -- )
        {
            result 
*=  a;
            
while (result  >   9 )
            {
                result 
%=   10 ;
            }
            
for ( int  i  =   0 ; i  <   10 ; i ++ )
            {
                
if (yushu[i]  ==  result)
                {
                    has 
=   1 ;
                    
break ;
                }
            }
            
if (has  ==   1 )
                
break ;
            
else
            {
                yushu[cap] 
=  result;
                cap
++ ;
            }
        }
        
if (has  ==   1   &&  cap  !=   0 )
        {
            pos 
=  b  %  (cap)  -   1 ;
            
if (pos  ==   - 1 )
                pos 
=  cap  -   1 ;
            cout 
<<  yushu[pos]  <<  endl;
        }
        
else
            
if (has  !=   1 )
                cout 
<<  result  <<  endl;
        
if (has  ==   1   &&  cap  ==   0 )
            cout 
<<   0   <<  endl;
        result 
=   1 ;
        a 
=   0 ;
        b 
=   0 ;
        
for ( int  i  =   0 ; i  <   10 ; i ++ )
        {
            yushu[i] 
=   0 ;
        }
    }
    
return   0 ;
}

你可能感兴趣的:(em)