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 |
Re:很奇怪的一个问题,咋相差就这么大 16MS VS TLEIn Reply To:很奇怪的一个问题,咋相差就这么大 16MS VS TLE Posted by:dynamic_study at 2009-08-20 17:35:53 > TLE: > #include<stdio.h> > #include<math.h> > int main() > { > int s; > int ans,n; > while(scanf("%d",&n)!=EOF) > { > s=1; > ans=1; > while(s%n!=0) > { > s=s*10+1; > ans++; > } > printf("%d\n",ans); > } > return 0; > } > AC,16MS: > #include<stdio.h> > #include<math.h> > int main() > { > int s; > int ans,n; > while(scanf("%d",&n)!=EOF) > { > s=1; > ans=1; > s%=n; > while(s) > { > s=s*10+1; > ans++; > s%=n; > } > printf("%d\n",ans); > } > return 0; > } 因为(a+b)%c等价于((a%c)+(b%c))%c Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator