UVA 10791

简介:

题目链接:https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1732
hint:素因子分解

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
int main()
{
    int m,ss,flag,cnt;
    int cas=1;
    while(scanf("%d",&m),m)
    {
        LL ans=0;
        ss=(int)sqrt((double)m+0.5);//不要ss=吗;
        flag=0;
        for(int i=2; i<=ss; i++)//注意这里千万不要i*i<=ss啊!!!
        {
            if(m % i == 0)
            {
                flag++;
                cnt=1;
                while(m % i == 0)
                {
                    cnt*=i;
                    m/=i;
                }
                ans+=cnt;
            }
        }
        if(flag == 0)
            ans=(LL)m+1;
        else if(m>1 || flag == 1)
            ans+=m;
        printf("Case %d: %lld\n",cas++,ans);
    }
    return 0;
}
目录
相关文章
UVa11968 - In The Airport
UVa11968 - In The Airport
62 0
|
算法
UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494...
1577 0
|
机器学习/深度学习
uva 11538 Chess Queen
点击打开链接 题意:给定一个n*m的矩阵,问有多少种方法放置两个相互攻击的皇后?规定在同一行同一列和同对角线的能够相互攻击 思路: 1 先考虑同一行的情况,n行就有n种情况,每一行有m*(m-1)种,总的是n*m*(m-1); 2 考虑同...
830 0
|
机器学习/深度学习 人工智能
uva 10870 Recurrences
点击打开uva 10870 思路:构造矩阵+矩阵快速幂 分析: 1 题目给定f(n)的表达式 f(n) = a1 f(n - 1) + a2 f(n - 2) + a3 f(n -3) + .
742 0
uva 10273 Eat or Not to Eat?
点击打开链接uva 10273 思路: 暴力求解 分析: 1 题目要求没有吃掉的奶牛的个数已经最后一次吃掉奶牛的天数 2 没有其它的方法只能暴力,对于n头牛的n个周期求最小公倍数,然后在2个公倍数之内暴力求解 代码: #inclu...
836 0
|
人工智能
uva 10189 Minesweeper
/* Minesweeper WA了n次才知道uva格式错了也返回wa没有pe啊尼玛 */ #include&lt;iostream&gt; #include&lt;stdio.h&gt; #include&lt;string.h&gt; using namespace std; char a[105][105]; int main() { int i,j,n,m,
944 0
uva 1394 - And Then There Was One
点击打开链接uva 1394 思路: 数学递推 分析: 1 题目是一道变形的约瑟夫环变形问题 2 网上看到一篇很好的数学递推法 问题描述:n个人(编号0~(n-1)),从0开始报数,报到(m-1)的退出,剩下的人继续从0开始报数。
1006 0
|
人工智能
uva 11300 - Spreading the Wealth
点击打开链接uva 11300 思路:数学分析+贪心 分析: 1 首先最终每个人的金币数量可以计算出来,它等于金币总数除以人数n。接下来我们用m来表示每人的最终的金币数 2 现在假设编号为i的人初始化为Ai枚金币,Xi表示第i个人给第i-1个人Xi枚金币,对于第一个人来说他是给第n个人。
873 0