poj 1730
来源:互联网 发布:教孩子学编程 编辑:程序博客网 时间:2024/05/14 21:24
数论唯一分解定理的应用,要注意负数的情况,想明白这个过程用了两个小时,后来因为一个while写成了if有调试了俩小时,为什么还是这么菜
数论唯一分解定理的应用,要注意负数的情况,想明白这个过程用了两个小时,后来因为一个while写成了if有调试了俩小时,为什么还是这么菜#include <iostream>#include <cmath>using namespace std;int gcd(int a,int b){if(b==0) return a;elsereturn gcd(b,a%b);}int main(){long long n;while(cin>>n&&n){int i,flag1=0;if(n<0){ n=-n;flag1=1;}int m=(int)sqrt((double)n);int ngcd=m,tem,t,ans=1,com=n,amount,flag=1;for(i=2;i<=m;i++){if(n%i==0){amount=0;while(n%i==0){n/=i;amount++;}if(flag1){while(amount%2==0)amount/=2;//得到了本素因子指数能够整除的最大奇数}if(flag) ngcd=amount;else{tem=ngcd;if(tem>amount){t=tem;tem=amount; amount=t;}ngcd=(amount,tem);}}}if(n!=1) ngcd=1;//如果经过上面那个循环,n不等于1,说明n还有素因子,且只有一个素因子,并且这个素因子的指数为1,可以通过证明得出,我已经证明过了 cout<<ngcd<<endl;}return 0;}
- poj 1730
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- Hypertable在Delete命令后执行Insert命令时应该注意的问题
- 《计算机网络基础》复习提纲
- ios:音频和视频(未完)
- 百度笔试题1
- android NinePatch使用教程--创建优美的背景图片
- poj 1730
- 自定义时钟控件
- js 中正则表达式使用详解
- 计算机网络复习重点
- 如何将Android应用程序编译至image/rom中
- 通过实例浅谈Spring运作机制
- [每日一学]MFC学习笔记——读取文本文档
- C#连接Oracle数据库
- ubuntu gtk eclipse