Uva 10892 - LCM Cardinality 解题报告(因式分解)

96 篇文章 0 订阅

Problem F
LCM Cardinality
Input: 
Standard Input

Output: Standard Output

Time Limit: 2 Seconds

 

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

 

Input

The input file contains at most 101 lines of inputs. Each line contains an integer N (0<N<=2*109). Input is terminated by a line containing a single zero. This line should not be processed.

 

Output

For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a single space.

 

Sample Input                             Output for Sample Input

2
12
24
101101291
0

2 2

12 8

24 11

101101291 5


Problem setter: Shahriar Manzoor

Special Thanks: Derek Kisman


    解题报告: 问最大公约数为n的数有多少对。首先,可以将n因式分解,写出p1^e1 * p2^e2 ... * pn*en。一对数中,必然至少有一个可以整除pi^ei,另外一个就有(1+ei)种情况。统计所有的情况,去重即可。代码如下:
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

void work(int n)
{
    int nn=n;
    int ans=1;

    for(int i=2;i*i<=n;i++) if(n%i==0)
    {
        int t=0;
        while(n%i==0) n/=i,t++;
        ans*=(t*2+1);
    }

    if(n>1)
        ans*=3;

    ans-=1;
    ans/=2;
    ans+=1;

    printf("%d %d\n", nn, ans);
}

int main()
{
    int n;
    while(~scanf("%d",&n) && n)
        work(n);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值