给定2个数,求出它们的最大公约素数
2014-06-16 00:42
197 查看
华为OJ上的题目,我的答案只有98分,可能还有1,2组数据没过。。。一下子不知道为什么,以后再研究,该睡觉了
j
j
#include <cstdio> #include <iostream> using namespace std; int gcd(int a,int b) { return a%b==0?b:gcd(b,a%b); } int main() { int n,m,i,ans; cin>>n>>m; int t,tmp=gcd(n,m); if(tmp==1)ans=0; t=tmp; while(t>1) { for(i=2;i<=t;i++) { while(t%i==0) { t=t/i; ans=i; } } } cout<<ans<<endl; return 0; }
相关文章推荐
- 给定两个数m,n,使用欧几里得的辗转相除法求出它们的最大公约数
- 奇偶数and素数and最大公约数and最小倍数
- 最大公约数,最小公倍数,求素数,偶数,奇数
- 动态函数调用实现下列操作,输入2个数以及操作符计算结果。@求最大公约数 $求最小公倍数 -求差 +求和
- SICP学习笔记:最大公约数和素数检测
- 特殊数求解(最大公约数/最小公倍数/素数)
- 定义:整除、素数与合数、公约数和最大公约数、互素(既约)、公倍数和最小公倍数以及同余
- 最大公约数,最小公倍数,素数等问题
- 求2个数的最大公约数
- PTA教辅 求n以内最大的k个素数以及它们的和
- 素数和最大公约数
- Codeforces Round #375 (Div. 2) F. st-Spanning Tree(给你n个点,m条边,有两个给定的点S,T以及它们在生成树中最大的度数)
- 动态函数调用实现下列操作,输入2个数以及操作符计算结果。@ 求最大公约数 $求最小公倍数 - 求差 + 求和 等等
- ACM学习历程20——竞赛中的简单数学问题之最大公约数、素数表、排列组合数
- 输入2个正整数A,B,求A与B的最大公约数。 Input 2个数A,B,中间用空格隔开。(1<= A,B <= 10^9) Output 输出A与B的最大公约数。
- 抓其根本(一)(hdu2710 Max Factor 素数 最大公约数 最小公倍数.....)
- 抓其根本(一)(hdu2710 Max Factor 素数 最大公约数 最小公倍数.....)
- 算法如功夫——C++输入两个数求它们的最大公约数
- C语言实现2个数的最大公约数
- 求2个数的最小公倍数和最大公约数