Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
有没有不开数组的算法啊一定要把N!结果算出来才可以么? #include <stdio.h> int main() { int t,b,p,j,i,temp,jw,dl; int d[780]; scanf("%d",&t); while(t--) { d[1]=1; dl=1; scanf("%d %d",&b,&p); for(i=1;i<=b;i++) { jw=0; for(j=1;j<=dl;j++) { temp=d[j]*i+jw; d[j]=temp%10; jw=temp/10; } if(jw!=0) { while(jw>=10) { d[j++]=jw%10; jw/=10; } d[j]=jw; dl=j; } } temp=0; for(i=1;i<=j;i++) if(p==d[i]) temp++; printf("%d\n",temp); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator