开始寻思半天是什么算法==原来是这货==注意答案开头有0的处理 机智如我
| description | 
| <tt> 求出X^X(X的X次方)后四位的数值。</tt> | 
| input | 
| <tt> 测试数组有多组,每行输入一个整数x,(1<=x<=100000000)</tt> | 
| output | 
| <tt> 对于每次输入,对应输出相应x的后四位数,每个输出占一行。</tt> | 
| sample_input | 
| <tt> 1 2 3 10</tt> | 
| sample_output | 
| <tt> 1 4 27 0000</tt> | 
#include <iostream>
#include<cstdio>
using namespace std;
long long quickmod(long long a,long long b)
{
     long long ans=1;
     while(b)
     {
          if(b&1)
          {
               ans=(ans*a)%10000;
          }
          b/=2;
          a=a*a%10000;
     }
     return ans;
}
int main()
{
    long long x;
    while(~scanf("%lld",&x))
    {
         if(x==0) printf("0\n");
         else
         {
         long long ans=quickmod(x,x);
         if(x<6) printf("%lld\n",ans);
         else printf("%04lld\n",ans);
         }
    }
    return 0;
}

 京公网安备 11010502036488号
京公网安备 11010502036488号