Uva10791

宿舍一过十点就断电是个问题,真是应了一句话,断电除了能阻挡我们学习,什么也阻挡不了,摊手,—_—

昨天晚上做的题目吃鸡6到飞起,我喜欢,其他没什么好说的,发个在刷专题的题目

 

LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multiple of all integers of that set. It is interesting to note that any positive integer can be expressed as the LCM of a set of positive integers. For example 12 can be expressed as the LCM of 1, 12 or12, 12 or 3, 4 or 4, 6 or 1, 2, 3, 4 etc.

In this problem, you will be given a positive integer N. You have to find out a set of at least two positive integers whose LCM is N. As infinite such sequences are possible, you have to pick the sequence whose summation of elements is minimum. We will be quite happy if you just print the summation of the elements of this set. So, for N = 12, you should print4+3 = 7 as LCM of 4 and 3 is 12 and 7 is the minimum possible summation.

 

Input 

The input file contains at most 100 test cases. Each test case consists of a positive integer N ( 1N231 - 1).

Input is terminated by a case where N = 0. This case should not be processed. There can be at most 100 test cases.

 

Output 

Output of each test case should consist of a line starting with `Case #: ' where # is the test case number. It should be followed by the summation as specified in the problem statement. Look at the output for sample input for details.

 

Sample Input 

 

 
12
10
5
0

 

Sample Output 

 

 
Case 1: 7
Case 2: 7
Case 3: 6

题意:图片部分的意思,分解质因子

思路:如果n是素数,直接输出n+1即可

注意的一点在于该数只有一个质因数的时候,因为要满足最小公倍数是这个数,所以输出质因子相应次方+1

 

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#define ll long long
#define N 100001
#define mod 10
using namespace std;
ll prime[N],vis[N];
ll pow(ll a,ll b)
{
    ll ans=1;
    ll base=a;
    while(b!=0)
    {
        if(b&1!=0)
            ans*=base%mod;
        base*=base%mod;
        b>>=1;
    }
    return ans;
}
void Oula(int n)
{
    int k=1;
    for(int i=2;i<n;i++)
    {
        if(!vis[i])
            prime[k++]=i;
        for(int j=1;j<k&&i*prime[j]<n;j++)
        {
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)
            break;
        }
    }
}
int main()
{
    ll n;
    int cas=1;
    while(cin>>n)
    {
        if(n==0)
            break;
        ll ans=0;
        ll temp1=n,temp2=1;
        ll num=0;
        for(ll i=2;i<=sqrt(n)+2;i++)
        {
            if(temp1%i==0)
            {
                num++;
                temp2=1;
                while(temp1%i==0)
                {
                    temp1/=i;
                    temp2*=i;
                }
                ans+=temp2;
            }
        }
        if(temp1==n)
            ans=1+n;
        else if(num==1||temp1!=1)
                ans+=temp1;
        cout<<"Case "<<cas++<<": "<<ans<<endl;
    }
    return 0;
}

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值