2991:2011

2991:2011

总时间限制:
1000ms
内存限制:
65536kB
描述
已知长度最大为200位的正整数n,请求出2011^n的后四位。
输入
第一行为一个正整数k,代表有k组数据,k<=200接下来的k行,

每行都有一个正整数n,n的位数<=200
输出
每一个n的结果为一个整数占一行,若不足4位,去除高位多余的0
样例输入
3
5
28
792
样例输出
1051
81
5521
 1 #include <math.h>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <string.h>
 5 #include <time.h>
 6 #include <queue>
 7 #include <vector>
 8 #include <algorithm>
 9 #include <functional>
10 #include <iostream>
11 using namespace std;
12 int n=500,o,i,p;
13 int cas,a[505]={0,2011},length,x;
14 char c[205];
15 int main()
16 {
17 for (i=2;i<=n;i++)
18 {
19 a[i]=(a[i-1]*2011)%10000;
20 }
21 scanf ("%d",&cas);
22 for (i=1;i<=cas;i++)
23 {
24 memset (c,0,sizeof(c));
25 x=0;
26 scanf ("%s",c);
27 length=strlen(c);
28 if (length>=3)
29 {
30 for (o=length-3;o<=length-1;o++)
31 x=x*10+c[o]-'0';
32 }
33 else
34 x=(int)atof(c);
35 if (x<=500)
36 printf ("%d\n",a[x]);
37 else
38 printf ("%d\n",a[x-500]);
39 }
40 return 0;
41 }

 

posted @ 2017-03-24 21:02  自为风月马前卒  阅读(486)  评论(0编辑  收藏  举报

Contact with me