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 |
帮我看看,测试数据都对,就是不能通过#include <cstdio> using namespace std; int pow(int base, int n){ int result = 1; for(int i = 0; i < n; ++i){ result *= base; } return result; } int main(){ int B, N; int p1, p2; scanf("%d %d", &B, &N); while(true){ if((B == 0) && (N == 0)) { break; }else { if(B == 1){ printf("1\n"); }else{ for(int i = 0; i < 1001; ++i){ p1 = pow(i, N); p2 = pow(i + 1, N); if(p1 <= B && p2 >=B){ if(B - p1 > p2 - B){ printf("%d\n", i + 1); }else{ printf("%d\n", i); } break; // already get the answer, quit } } } } scanf("%d %d", &B, &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