TOJ 3987.Hacb knows the gift

题目链接:http://acm.tju.edu.cn/toj/showp3987.html


3987.    Hacb knows the gift
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 1228    Accepted Runs: 284



Coach Yu will send gifts to ACM teammates. This message was known by Hacb, he send the message to G.D.R at once. But the message was encrypted. If Hacb wants to send an integer x to G.D.R, the massage will be encrypted as F(x) which F(x) = x^3. Now G.D.R get the F(x), please help him to get the message x.
Hoverer, the message may be changed by error. So if you can't find the x which satisfy F(x) = x^3 you should output "Wrong Message!"

Input

First line is a number t . Then t lines follows. Each line contains a number n, |n|≤10^18

Output

Output the number x on a line which x^3 = n ,but if the x not exist output "Wrong Message!"
Output a line between two results.

Sample Input

2
8
7

Sample Output

2

Wrong Message!



Source: TJU Team Selection 2013
Submit   List    Runs   Forum   Statistics


水题,注意pow结果的精度问题。


#include <stdio.h>
#include <cmath>
int main()
{
	long long t,n,l,i,tag=0;
	scanf("%lld",&t);
	while(t--){
		scanf("%lld",&n);
		if(tag==1)
			printf("\n");
		tag=1;
		if(n<0)
		{n=-n;l=-1;}
		else
			l=1;
		long long tmp=(long long)pow(n,1.0/3.0);
		//printf("%lld",tmp);
		for(i=tmp-1;i<=tmp+1;i++)
			if(i*i*i==n){
				printf("%lld\n",i*l);
				break;
			}
		if(i==tmp+2)
			printf("Wrong Message!\n");
	}
 } 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值