| ||||||||||
| 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 | |||||||||
水过,0ms,布吉岛熊不熊不用龍龍int,反正用了肯定可以#include <iostream>
#include <stdio.h>
using namespace std;
long long int pw(long long int n, long long int p){
if(p == 0) return 1;
long long e = pw(n, p/2);
if(p & 1) return e*e*n;
return e*e;
}
int main() {
while(1){
long long int N;
scanf("%I64d", &N);
if(N < 0) break;
long long int mxK = 0;
for(long long int k = 2; ; k++){
long long int kk = pw(k,k);
if(kk-k>N) break;
if((N+k-1)%kk != 0) continue;
long long int lk_1 = (N+k-1)/kk;
if(lk_1 <= 0) continue;
if(k%2==0 && lk_1%k==k-1) mxK = k;
if(k%2!=0 && lk_1%k==1) mxK = k;
}
if(mxK > 0) printf("%I64d coconuts, %I64d people and 1 monkey\n", N, mxK);
else printf("%I64d coconuts, no solution\n", 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