Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

很奇怪的一个问题,咋相差就这么大 16MS VS TLE

Posted by dynamic_study at 2009-08-20 17:35:53 on Problem 2551 and last updated at 2009-08-20 17:37:25
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;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator