3987 D. Hacb knows the gift
来源:互联网 发布:js添加css3动画效果 编辑:程序博客网 时间:2024/06/05 12:07
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!
题意:求一个数是否能开3次方。
用二分法来做。(要注意输出格式,负数的时候,0的时候)左边有0开始,右边由1e6开始。
#include <cstdio>#include <algorithm>#include <cstring>#include <iostream>#include <cmath>#include <cstdlib>using namespace std;int main (void){ int n; cin>>n; while(n--) { int flag=1;int mark=0; long long num; scanf("%lld",&num); if(num<0) { flag=-1; num=num*(-1); } long long lb=0,ub=1e6; while(ub-lb>1) { int mid=(lb+ub)/2; /*if(num%(mid*mid)!=0) { mark=1; break; }*/ if(num/(mid*mid)<=mid)//乘法改除法 { ub=mid; } else { lb=mid; } //lb+1=ub; } if(ub*ub*ub==num||lb*lb*lb==num) { if(ub*ub*ub==num) printf("%lld\n",ub*flag); if(lb*lb*lb==num) printf("%lld\n",lb*flag); } else printf("Wrong Message!\n"); if(n!=0) printf("\n"); } return 0;}
- 3987 D. Hacb knows the gift
- TJU Hacb knows the gift
- TOJ 3987.Hacb knows the gift
- The Doctor Knows Better
- The best gift
- The Best Gift
- The Best Gift
- codeforces_609B. The Best Gift
- The Best Gift
- How the iPhone knows where you are
- The gift is the present
- UVa 10889 - The Lost Gift
- GIFT
- gift
- Gift
- Who Should Be Given the Gift?
- Codeforces 609B The Best Gift 【水题】
- CodeForces 609B The Best Gift
- 3985. I guess the gift is a bag!
- GCD的常见用法
- 在C# project中添加引用的System.Configuration的过程:
- Java二维数组_三角
- 洛谷 P1082 同余方程
- 3987 D. Hacb knows the gift
- L2-001. 紧急救援(dijkstra+记录路径)
- iterm2上传下载文件
- 基于 flask 框架的模拟instagram 图片分享网站的开发 4
- AutoCompleteTextView概述
- c++中STL库简介及使用说明
- spring 集成shiro 之 自定义过滤器
- 求某个数范围内的素数个数
- UIWebView与JavaScript(JS) 回调交互