用辗转相除法,开O2后#7#8#10TLE
查看原帖
用辗转相除法,开O2后#7#8#10TLE
715774
Little_Andyyu楼主2022/9/1 22:01
#include<bits/stdc++.h>
using namespace std;
int jk(int o,int q)
{
	return o>q?o:q;
}
int z(int argc,int h)
{
	return argc<h?argc:h;
}
int gcd(int v,int w)
{
	if(v%w==0){
		return w;
	}
	else return gcd(w,v%w);
}
int lcm(int x,int y)
{
	return x*y/gcd(x,y);
}
int main()
{
	int a,b;
	cin>>a>>b;
	int f=0;
	if(a>b){
		cout<<0;
	return 0;}
	if(b%a!=0)
	{
		cout<<0;
		return 0;
	}
	for(int i=z(a,b);i<=jk(a,b);i++){
		for(int j=z(a,b);j<=jk(a,b);j++){
			if(gcd(i,j)==a&&lcm(i,j)==b){
				f++;
			}
		}
	}cout<<f;
	return 0;
}
2022/9/1 22:01
加载中...