zoukankan      html  css  js  c++  java
  • 题解 UVa10892

    题目大意 多组数据,每组数据给定一个整数 \(n\),求满足 \(LCM(x,y)=n\) 的不同无序整数对 \((x,y)\) 的数目。

    分析 若有 \(LCM(x,y)=n\),则有 \(GCD(n/x,n/y)=1\),问题便转化为了求 \(n\) 的所有因数中互质的数量,枚举即可。

    #include<bits/stdc++.h>
    using namespace std;
    
    int n, ans;
    int tot, fac[40000];
    
    int gcd(int x, int y)
    {
    	if(!y) return x;
    	return gcd(y, x % y);
    }
    
    int main()
    {
    	while(~scanf("%d", &n) && n) {
    		tot = ans = 0;
    		
    		for(int i = 1; i * i <= n; ++i) {
    			if(!(n % i)) {
    				fac[++tot] = i;
    				if(i * i != n) fac[++tot] = n / i;
    			}
    		}
    		
    		for(int i = 1; i <= tot; ++i)
    			for(int j = i; j <= tot; ++j)
    				ans += gcd(fac[i], fac[j]) == 1;
    		
    		printf("%d %d\n", n, ans);
    	}
    }
    
  • 相关阅读:
    Hadoop
    Mapreduce
    ssh原理
    HDFS
    Centos
    创建jira插件
    新型的领导者是一名推动者,而不是一名发号施令者
    上善若水,虚怀若谷
    GoAhead 嵌入式web
    Eclipse基金会
  • 原文地址:https://www.cnblogs.com/whx1003/p/11744137.html
Copyright © 2011-2022 走看看