UVA 10892-LCM Cardinality

A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, thenumber of different integer pairs with LCM is equal to N can be called the LCM cardinality of thatnumber N. In this problem your job is to find out the LCM cardinality of a number.


题意:现在给你1个数字C,让你求有多少对的数字的最小公倍数数是C。


思路:由于数字的最小公倍数是C,那么他肯定是C的因子,

暴力求出所有C的因子,然后在一步一步进行比较,判断就行了。暴力。

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int n,cnt;
int num[100000];
void chuli(){
    int sum=2;
    cnt=0;
    for(int i=2;i<=sqrt(n);i++)
        if(n%i==0){
            num[cnt++]=i;
            if(i==n/i)continue;
            num[cnt++]=n/i;
            }
    sum+=cnt;
    for(int i=0;i<cnt;i++)
        for(int j=i+1;j<cnt;j++)
            if(num[i]*num[j]==__gcd(num[i],num[j])*n){
                //printf("%d %d\n",num[i],num[j]);
                sum++;}
    printf("%d %d\n",n,sum);
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        if(n==0) break;
        if(n==1){
            printf("1 1\n");
            continue;
        }
        chuli();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值