uva10622 Perfect P-th Powers
2016-01-07 19:18
344 查看
留坑(p.343)
完全不知道哪里有问题qwq
从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊
View Code
完全不知道哪里有问题qwq
从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> using namespace std; void setIO(const string& s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } template<typename Q> Q read(Q& x) { static char c, f; for(f = 0; c = getchar(), !isdigit(c); ) if(c == '-') f = 1; for(x = 0; isdigit(c); c = getchar()) x = x * 10 + c - '0'; if(f) x = -x; return x; } template<typename Q> Q read() { static Q x; read(x); return x; } typedef long long LL; LL qpow(LL a, LL b, LL Lim = ~0ull >> 1) { for(LL c = 1; ; a *= a) { if(b & 1) c *= a; if(!(b >>= 1)) return c; if(c > Lim || a > Lim) return -1; } } bool exist(LL x, LL p) { int l = 0, r = ~0u >> 1; while(l <= r) { int mid = l + (r - l) / 2; LL res = qpow(mid, p, x); if(res == x) return 1; else if(res == -1 || res > x) r = mid - 1; else l = mid + 1; } return 0; } int solve(LL n) { if(n == 1) return 1; int sign = 1; if(n < 0) sign = -1, n = -n; for(int p = 31; p >= 2; p -= (sign > 0 ? 1 : 2)) { if(exist(n, p)) return p; } return 1; } int main() { #ifdef DEBUG freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int n; while(read(n)) { printf("%d\n", solve(n)); } return 0; }
View Code
相关文章推荐
- 利用JS函数制作时钟运行程序
- JavaScript规范
- JSPatch中的OC高级语法
- Node.js学习笔记(一)-认识Node.js
- Mac下文本编辑器无法生成html文件
- react学习笔记
- HTML-Day01-2
- HTML 空白
- js事件绑定及冒泡、捕获和默认行为处理
- 利用 Fragment ,JSON,第三方开源框架实现 仿新闻界面
- IntelliJ IDEA :Error:(1, 1) java: 非法字符: '\ufeff'
- 响应式web设计(css)
- Html5添加支持触摸屏的响应式轮播图插件教程
- HTML-Day01-1
- jstl中处理日期格式,小数,数字,百分比 fmt
- CSS Selector(berserkjs用到)
- ExtJs combobox 下拉图标
- CSS基础之颜色值和长度值设置
- Html5添加小巧的自定义页面加载loading指示器插件教程
- jstl fn:replace替换换行符