Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 水过，0ms，布吉岛熊不熊不用龍龍int，反正用了肯定可以

Posted by KatrineYang at 2016-09-12 12:34:20 on Problem 1309
```#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: