N!Again
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 23 Accepted Submission(s) : 10
Problem Description
WhereIsHeroFrom: Zty, what are you doing ?
Zty: I want to calculate N!......
WhereIsHeroFrom: So easy! How big N is ?
Zty: 1 <=N <=1000000000000000000000000000000000000000000000…
WhereIsHeroFrom: Oh! You must be crazy! Are you Fa Shao?
Zty: No. I haven's finished my saying. I just said I want to calculate N! mod 2009
Hint : 0! = 1, N! = N*(N-1)!
Zty: I want to calculate N!......
WhereIsHeroFrom: So easy! How big N is ?
Zty: 1 <=N <=1000000000000000000000000000000000000000000000…
WhereIsHeroFrom: Oh! You must be crazy! Are you Fa Shao?
Zty: No. I haven's finished my saying. I just said I want to calculate N! mod 2009
Hint : 0! = 1, N! = N*(N-1)!
Input
Each line will contain one integer N(0 <= N<=10^9). Process to end of file.
Output
For each case, output N! mod 2009
Sample Input
4 5
Sample Output
24 120
题解:(a+b)%2009=a%2009+b%2009;而任一个数如果大于2009就可以写成a=(2009*x+b)再与另外一个数相乘有用的就是b也就是amod(%)2009;
代码:
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int temp,N; 6 while(~scanf("%d",&N)){temp=1; 7 for(int i=1;i<=N;i++){ 8 temp*=i; 9 if(temp>=2009)temp%=2009; 10 if(i>2009)break; 11 } 12 printf("%d ",temp); 13 } 14 return 0; 15 }
1sting
Time Limit : 5000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 35 Accepted Submission(s) : 10
Problem Description
You will be given a string which only contains ‘1’; You can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. Surly, you may get many different results. For example, given 1111 , you can get 1111, 121, 112,211,22. Now, your work is to find the total number of result you can get.
Input
The first line is a number n refers to the number of test cases. Then n lines follows, each line has a string made up of ‘1’ . The maximum length of the sequence is 200.
Output
The output contain n lines, each line output the number of result you can get .
Sample Input
3 1 11 11111
Sample Output
1 2 8
题解:大数斐波那契;
代码:
1 #include<stdio.h> 2 #include<string.h> 3 #define MAX(x,y) x>y?x:y 4 char a[201][1010]; 5 void bignum(char *x,char *y,int v){int c[1010],d[1010],z[1010]; 6 int t,t1,t2,i,j; 7 memset(c,0,sizeof(c)); 8 memset(d,0,sizeof(d)); 9 memset(z,0,sizeof(z)); 10 t1=strlen(x); 11 t2=strlen(y); 12 t=MAX(t1,t2); 13 for(i=t1-1,j=0;i>=0;i--,j++)c[j]=x[i]-'0'; 14 for(i=t2-1,j=0;i>=0;i--,j++)d[j]=y[i]-'0'; 15 for(i=0;i<t;++i){ 16 z[i]=c[i]+d[i]+z[i]; 17 if(z[i]>9)z[i+1]++,z[i]%=10; 18 if(z[t])t++; 19 } 20 for(i=t-1,j=0;i>=0;i--,j++){ 21 a[v][j]=z[i]+'0'; 22 } 23 a[v][j]='