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的,难道是超出int范围导致错误?

Posted by tdzl2003 at 2005-08-02 20:23:52 on Problem 2407
#include <iostream>
#include <cmath>
using namespace std;

int List[1000000],ListL;
int Ar[100],Value;
int n;

void test(int a,int b,int c)
{
	int r;
	for (r=b;r<ListL && List[r]*a<n;r++)
	{
		Value+=Ar[c]*((n-1)/(List[r]*a));
		test(List[r]*a,r+1,c+1);
	}
}

int main()
{
	int i,n1;
	Ar[1]=-1;
	for (i=2;i<100;i++)
        Ar[i]=Ar[i-1]*(1-i);
	while (cin>>n && n)
	{
		Value=n-1;
		ListL=0;
		if (n%2==0) List[ListL++]=2;
		n1=n;
		while (n1%2==0)
			n1/=2;
		for (i=3;n1>1;i+=2)
			if (n1%i==0)
			{
				List[ListL++]=i;
				while (n1%i==0) 
					n1/=i;
			}
		test(1,0,1);
		cout<<Value<<endl;
	}
}

//WA

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