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

输入1 1应该输出什么?不应该是1么?怎么过的程序都输出0啊?(附我的不AC代码……)

Posted by goodness at 2009-07-20 20:57:07 on Problem 1091
#include <iostream>
#include <cmath>
using namespace std;

typedef long long i64;
i64 pf[110000],pfNum,mn,d[110000],n,m,t,change;

void getChange(i64 btm,i64 now,i64 top)
{
	i64 get=m,i;
	if(now==top)
	{
		for(i=0;i<top;i++) get/=d[i];
		change+=i64(pow(double(get),double(n)));
	}
	else for(i=btm;i<pfNum;i++) d[now]=pf[i],getChange(i+1,now+1,top);
}

int main()
{
	i64 i,ans,mm;
	while(cin>>n>>m)
	{
		pfNum=0; mm=m;
		for(i=2;i*i<=mm;i++)
		{
			if(mm%i==0)
			{
				while(mm%i==0) mm/=i;
				pf[pfNum++]=i;
			}
		}
		if(mm!=1) pf[pfNum++]=mm;
		ans=mn=i64(pow(double(m),double(n)));
		for(i=0;i<pfNum;i++)
		{
			change=0;
			getChange(0,0,i+1);
			if(i%2) ans+=change;
			else ans-=change;
		}
		cout<<ans<<endl;
	}
	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