Perfect P-th Powers UVA
来源:互联网 发布:网络舞蹈培训学校 编辑:程序博客网 时间:2024/06/04 23:26
将得到的数进行分解,也就是找出该素数所有的素因子以及素因子对应的指数,那么问题也就转化成求解这些素因子的最大公约数。素数可以打表得到,另外需要注意输入的数据为1的情况也就是对应的下边的代码中ans为0的情况,同时要注意处理输入的数据是负数的情况,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>#include<functional>using namespace std;const int maxn = 600000;int vis[maxn + 5];vector<int> prime;void Init(){memset(vis,0,sizeof(vis));vis[0] = vis[1] = 1;int up = floor(sqrt(maxn) + 0.5);for (int i = 2; i <= up; i++){if (!vis[i]){for (long long j = i*i; j <= maxn; j += i)vis[j] = 1;}}for (int i = 2; i <= maxn; i++)if(!vis[i]) prime.push_back(i);}int gcd(int a, int b){if (!b) return a;return gcd(b, a%b);}long long N;int main(){Init();while (cin >> N){bool flag = false;if (N < 0){N = -N;flag = true;}if (N == 0) break;int ans = 0;int n = prime.size();for (int i = 0; i < n && prime[i] <= N; i++){int amount = 0;if (N%prime[i] == 0){while (N%prime[i]==0){N = N/prime[i];amount++;}}ans = gcd(ans,amount);}if (ans == 0) ans = 1;if (flag){while (ans % 2 == 0)ans = ans / 2;}cout << ans << endl;}return 0;}
阅读全文
0 0
- Perfect P-th Powers UVA
- UVa 10622 - Perfect P-th Powers
- UVA 10622 - Perfect P-th Powers(数论)
- uva 10622 - Perfect P-th Powers(数论)
- UVA - 10622 Perfect P-th Powers
- UVA 10622 - Perfect P-th Powers
- UVa 10622 - Perfect P-th Powers
- UVa 10622 - Perfect P-th Powers
- UVa10622 Perfect P-th Powers
- UVA 10622 Perfect P-th Powers(数论)
- UVa 10622 - Perfect P-th Powers(数论)
- uva 10622——Perfect P-th Powers
- UVa 10622 - Perfect P-th Powers(对数+快速幂)
- UVA 10622 Perfect P-th Powers (唯一分解定理 + GCD)
- 10622 - Perfect P-th Powers(唯一分解定律)
- UVA 10622(p343)----Perfect Pth Powers
- POJ 1730 Perfect Pth Powers (求最大p,x=b^p)
- poj1730 - Perfect Pth Powers
- 数据库的增删改查
- zoj--3983(CCPC秦皇岛)
- 51Nod-1264-线段相交
- html中使用div块级元素布局的两种方法
- python图像读取、修改和绘制
- Perfect P-th Powers UVA
- 汇编中偏移地址的理解
- Android 超简单音乐播放器(三)根据歌曲名或者歌手搜索本地音乐(EditText监听)
- 网络书签
- java用类实现结构体数组功能
- TextBox RadioButton
- 秒杀系统架构优化思路
- JavaScript的外部对象
- 1037. 在霍格沃茨找零钱(20)