Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
小菜鸟向各位大牛请教,我这个算法为何WA,虽说是暴力枚举……但测试数据都对啊……求数据#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator