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

水过,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:

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