1029
  • 板块题目总版
  • 楼主封禁用户
  • 当前回复6
  • 已保存回复6
  • 发布时间2019/2/15 11:43
  • 上次更新2024/9/28 11:39:04
查看原帖
1029
118086
封禁用户楼主2019/2/15 11:43

为什么加上判是否是平方数不对呢

#include<iostream>
#include<cstdio>
#include<cmath> 
using namespace std;
inline int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int main(){
	int ff=0;
	int m,n,ans=0;   //初始化 
	scanf("%d%d",&n,&m);
	int tot=n*m;
	//if(sqrt(tot)*sqrt(tot)==tot) ff=-1;
    //为什么不特判
	for(register int i=1;i*i<=tot;i++){
		if(gcd(i,tot/i)==n&&tot%i==0) ans++;  //注意条件 
	}
	printf("%d\n",ans*2+ff);  //注意只搜了一半 
	return 0;
}

/* (15,12)!=(12,15)*/ 
2019/2/15 11:43
加载中...