uva 10791

参考紫书:先贴一个唯一分解定理的公式:N=P1a1P2a2P3a3......Pnan。

题意:给一个数n,求出一些数,他们的最小公倍数为n(至少两个数)。

那么根据唯一分解定理,这些数就是P1a1P2a2P3a3......Pnan。

因为这些数是互质的,所以他们就是n的最小的因子们。

求因子的时候最多有一个因子大于floor(sqrt(n) + 0.5)。如果有两个他们的乘积不是比n还大了吗?-_-

/*
ID: DickensTone
LANG: C++
PROB: palsquare
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
const int maxn = 33;
int div_num(int &n, int f)
{
    int x = 1;
    while(n % f == 0) {n = n / f; x *= f;}
    return x;
}
void to_get(int n)
{
    int cnt = 0, t = n;
    long long ans = 0;
    int m = floor(sqrt(n) + 0.5);
    for(int i = 2; i <= m; i++)
    {
        if(n % i == 0)
        {
            cnt++;
            ans += div_num(n, i);
            //printf("%d\n", ans);
        }
    }
   // printf("%d\n", cnt);
   if(n > 1) {ans = ans + n; cnt++;}
   if(cnt <= 1) ans = t + 1LL;
   printf("%lld\n", ans);
}
int main()
{
    //freopen("palsquare.in","r",stdin);
    //freopen("palsquare.out","w",stdout);
    int n;
    int kase = 1;
    while(scanf("%d", &n) == 1 && n)
    {
        printf("Case %d: ", kase++);
        to_get(n);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值