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,虽说是暴力枚举……但测试数据都对啊……求数据

Posted by 3902100816 at 2011-07-21 15:03:51 on Problem 1730
#include <iostream>
#include <math.h>
using namespace std;
void pth(double n)
{
	double ans=1;
	double i;
	bool zf;
	if(n>0)zf=1;
	else zf=0;
	if(zf)
	{
		
		for(i=2;pow(n,1.00/i)>=2;i++)
		{
			if((fmod(pow(n,1.00/i),1.000))==0)//判断是否整数 
			{if(i>ans)ans=i;}
		}
	}
	else
	{
		n=-n;
		for(i=1;pow(n,1.00/i)>=2;i++)
		{
			if((fmod(pow(n,1.00/i),1.000))==0)
			{if(i>ans)ans=i;}
		}
		while(fmod(ans,2)==0.0)ans/=2;//负数不存在偶次根 
	}
	cout<<static_cast<int>(ans)<<endl;
}

int main()
{
	double n;
	while(cin>>n && n)
	{pth(n);}
	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