BUPT OJ 非平方等式
来源:互联网 发布:淘宝3000多的实体娃娃 编辑:程序博客网 时间:2024/05/22 05:17
纯粹数学题。如果无脑直接枚举肯定超时。
所以我就超时了。。。
后来分析了一下。
x^2+s(x)*x-n=0,能拆开成 x*(x+s(x))=n的形式,由于n小于10^18次方,x最大s(x)=162,所以能够得到不等式 sqrt(n)-162<=x<=sqrt(n);
剩下的就没啥了
/*USER_ID: test#bupt_wcyPROBLEM: 130SUBMISSION_TIME: 2017-01-26 21:04:55*/#include<iostream>#include<cmath>using namespace std;long long s(long long x){ long long temp=0; while(x) { temp+=x%10; x=x/10; } return temp; }int main(){ long long n; while(cin>>n) { long long RootOfN=sqrt(n); long long u=RootOfN-200>0?RootOfN-200:1; for(long long x=u;;x++) { if(x==sqrt(n-s(x)*x)) { cout<<x<<endl;break; } if(x>RootOfN){ cout<<"-1\n"; break; } } } }
0 0
- BUPT OJ 非平方等式
- 好题 BUPT OJ130 非平方等式
- kAri OJ130 非平方等式(二分加枚举)
- 平方等式问题
- BUPT OJ 147. Substring
- BUPT OJ 文件系统
- BUPT OJ 矩阵幂
- BUPT OJ IP地址
- BUPT OJ 寻找宝藏
- BUPT OJ 虚数
- BUPT OJ 统计节点个数
- BUPT OJ 最小距离查询
- BUPT OJ 96 矩阵幂
- BUPT OJ 101 IP地址
- 平方数 (sdut oj)
- FZU OJ 1707 等式数量
- OJ刷题---立方和等式
- BUPT OJ 中序遍历序列
- 聊天室
- HDU-1142-最短路+记忆化搜索
- LightOJ 1106 Gone Fishing 贪心, DP, 堆优化 2017年1月23日
- 笔记6
- 1031.Hello World for U (20)
- BUPT OJ 非平方等式
- noi-1703-与7无关的数
- HDU - 2222 Keywords Search AC自动机
- 机器学习面试准备(持续更新)--- 优秀博文传送门,收集优秀资源
- 可拆分物品背包问题
- SQL 不常用的一些命令sp_OACreate,xp_cmdshell,sp_makewebtask
- ifstream类使用心得一则
- 第三方视频播放器
- 欢迎使用CSDN-markdown编辑器