最小公倍数
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<limits.h> #include<algorithm> #include<queue> #include<vector> #include<set> #include<stack> #include<string> #include<sstream> #include<map> #include<cctype> using namespace std; bool isPrime(int num) { if (num == 2 || num == 3) { return true; } if (num % 6 != 1 && num % 6 != 5) { return false; } for (int i = 5; i*i <= num; i += 6) { if (num % i == 0 || num % (i+2) == 0) { return false; } } return true; } int minyue(int num,int num1) { int beic = num,gcd=1; for(int j=2;j<=beic;j++) { if(isPrime(j)&&beic%j==0&&num1%j==0) { beic = beic/j; gcd *= j; j = 1; } } return gcd; } int main() { int n,m; while(scanf("%d%d",&m,&n)!=EOF) { printf("%d",n*m/minyue(m,n)); } return 0; }
两数相乘/公约数.