uva10622 Perfect P-th Powers
留坑(p.343)
完全不知道哪里有问题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 = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
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 >> ) {
for(LL c = ; ; a *= a) {
if(b & ) c *= a;
if(!(b >>= )) return c;
if(c > Lim || a > Lim) return -;
}
} bool exist(LL x, LL p) {
int l = , r = ~0u >> ;
while(l <= r) {
int mid = l + (r - l) / ;
LL res = qpow(mid, p, x);
if(res == x) return ;
else if(res == - || res > x) r = mid - ;
else l = mid + ;
}
return ;
} int solve(LL n) {
if(n == ) return ;
int sign = ;
if(n < ) sign = -, n = -n;
for(int p = ; p >= ; p -= (sign > ? : )) {
if(exist(n, p)) return p;
}
return ;
} 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 ;
}
uva10622 Perfect P-th Powers的更多相关文章
- UVA 10622 - Perfect P-th Powers(数论)
UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...
- Perfect Pth Powers poj1730
Perfect Pth Powers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16383 Accepted: 37 ...
- UVA 10622 Perfect P-th Powers
https://vjudge.net/problem/UVA-10622 将n分解质因数,指数的gcd就是答案 如果n是负数,将答案除2至奇数 原理:(a*b)^p=a^p*b^p #include& ...
- Kattis之旅——Perfect Pth Powers
We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, ...
- POJ 1730 Perfect Pth Powers(暴力枚举)
题目链接: https://cn.vjudge.net/problem/POJ-1730 题目描述: We say that x is a perfect square if, for some in ...
- [暑假集训--数论]poj1730 Perfect Pth Powers
We say that x is a perfect square if, for some integer b, x = b 2. Similarly, x is a perfect cube if ...
- poj 1730 Perfect Pth Powers
这个有2种方法. 一种是通过枚举p的值(p的范围是从1-32),这样不会超时,再就是注意下精度用1e-8就可以了,还有要注意负数的处理…… #include<iostream> #incl ...
- UVa 10622 (gcd 分解质因数) Perfect P-th Powers
题意: 对于32位有符号整数x,将其写成x = bp的形式,求p可能的最大值. 分析: 将x分解质因数,然后求所有指数的gcd即可. 对于负数还要再处理一下,负数求得的p必须是奇数才行. #inclu ...
- Perfect Pth Powers pku-1730(筛+合数分解)
题意:x可以表示为bp, 求这个p的最大值,比如 25=52, 64=26, 然后输入x 输出 p 就是一个质因子分解.算法.(表示数据上卡了2个小时.) 合数质因子分解模板. ]; ]; ; ;n ...
随机推荐
- 将P2P虚拟货币(比特币、莱特币....)的算力用于公共的分布式计算的猜想
比特币最近几年非常火爆.发明者中本聪设计了一个特定的算法用于生成(发行)比特币,让各位玩家(矿工)用自己的CPU.显卡,或者更加专业的矿机,通过无聊的并行计算算出比特币的特定密码(挖矿).为了保证全网 ...
- AS3.0定义变量的访问范围
在AS3.0中变量的默认访问范围是:internal:包内成员可以访问,包外不可访问.AS2.0默认访问范围是public
- PHP获取当前页面完整url地址,包括参数的函数
//php获取当前访问的完整url地址 function get_current_url(){ $current_url='http://'; if(isset($_SERVER['H ...
- 如何便携使用github
Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.目前,包括Rubinius ...
- Jquery常用功能
jQuery 1.4给开发者带来了很多值得兴奋的新特性,同时使用jQuery的人也越来越多,为了方便大家对jQuery的使用,下面列出了一些jQuery使用技巧.比如有禁止右键点击.隐藏搜索文本框文字 ...
- Quartz1.8.5例子(四)
/* * Copyright 2005 - 2009 Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the ...
- Netflix工程总监眼中的分类算法:深度学习优先级最低
Netflix工程总监眼中的分类算法:深度学习优先级最低 摘要:不同分类算法的优势是什么?Netflix公司工程总监Xavier Amatriain根据奥卡姆剃刀原理依次推荐了逻辑回归.SVM.决策树 ...
- DJANGO不同应用之间的用户迁移
因为重新规划新的项目,数据库表结构和以前不一定了,但是想保存以前的很多用户认证方面的东东. 于是看了一下DJANGO的导入导出功能. ~~~~~~~~~~~~~~~~~~~ 数据导入: python ...
- MEMS Gyroscope Technology
InvenSense®Technology Overview Our technology is comprised of five coreelements: our patented Nasiri ...
- 解除網頁無法選取文字、鎖右鍵限制:Enable Copy(Chrome 擴充套件)
有些网页因会因为某些因素而禁止浏览者直接复制网页上的内容,虽然我们了解站方的意思,不过有些时候会造成一些不必要的困扰. Enable Copy 这款Chrome 扩充套件可以帮你一键解除封锁右键和选取 ...