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

测不动了!!!!!!!!!!!!!

Posted by yogafrank at 2008-08-30 09:26:44 on Problem 1730
我这边用了整数处理,应该。。。。

#include <iostream>
#include <cmath>
using namespace std;
#define in cin

int getpow ( int v, int k )
{
	if ( k == 1 )
		return v;
	else if ( k % 2 == 0 )
		return getpow ( v, k / 2 ) * getpow ( v, k / 2 );
	else
		return getpow ( v, k - 1 ) * v;
}

int main ()
{
	int n;

	while ( in >> n )
	{
		if ( n == 0 )
			break;

		int i = 1, result = -1, value;
		bool flag = true;

		if ( n < 0 )
		{
			flag = false;
			n = -n;
		}

		while ( ( value = (int) pow ( n * 1.0, 1.0 / i) ) > 1 )
		{
			if ( i > result && getpow ( value, i ) == n  )
				result = i;

			if ( flag )
				i++;
			else
				i += 2;
		}

		cout << result << endl;
	}

	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