题目链接:http://acm.tju.edu.cn/toj/showp3987.html
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
水题,注意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");
}
}