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

又wa了n次,那位高手可以提示一下?万分感谢!!!!

Posted by Loger at 2004-04-16 14:01:07 on Problem 1142
#include <stdio.h>
int check(int max,unsigned long num_tmp)//筛法
{
	int maxx=0;
	unsigned int i,sqr,j;
	unsigned long num=num_tmp;
	bool flag[65535];
	for(sqr=1;sqr*sqr<=num;sqr++);
	sqr--;
	for(i=0;i<=sqr;i++) flag[i]=false;
	for(i=2;i<=sqr&&i<=num;i++)
	{ 
		j=i;
		if(flag[i]==false&&num%i==0) 
		{
			j=i;
			while(j!=0) maxx+=j%10,j/=10;
			if(maxx>max) return 0;
			num/=i;
			j=i+i;
			i--;
		}
         while(j<=sqr&&j<=num) flag[j]=true,j+=i;
	}
   if(num==num_tmp) return 0;//这句话有没有都是wa,想问一下判断的数为素数时到底算不算?
   if(num!=1)
   {
	   while(num!=0) maxx+=num%10,num/=10;
   }
   if(maxx==max) return 1;
   else          return 0;
}
void main()
{
	unsigned long number,tmp,i;
	int  top;
	while(scanf("%ld",&number)!=-1&&number!=0)
	{
		if(number<0) continue;
		for(i=number+1;;i++)
		{
			top=0;
			tmp=i;
			while(tmp!=0) top+=tmp%10,tmp/=10;
			if(check(top,i)==1) break;
		}
		printf("%ld\n",i);
	}
}

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