UVA 10791
程序员文章站
2022-06-06 20:38:06
...
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<cmath>
#define maxn 10000000
using namespace std;
int a[maxn];
int b[maxn];
int n;
long long pow(int a,int b)
{
long long res=1;
while(b--)
res*=a;
return res;
}
void factor(int n,int &tot){
int temp,i,now;
temp=(int)((double)sqrt(n)+1);
tot=0;
now=n;
for(i=2;i<=temp;++i)if(now%i==0){
a[++tot]=i;
b[tot]=0;
while(now%i==0){
++b[tot];
now/=i;
}
}
if(now!=1){
a[++tot]=now;
b[tot]=1;
}
}
int id=1;
long long ans;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
long long num;
while(cin>>num)
{
if(num==0)break;
if(num==1)
{
cout<<"Case "<<id++<<": "<<2<<endl;continue;
}
ans=0;
factor(num,n);
if(n==1){cout<<"Case "<<id++<<": "<<1ll*pow(a[1],b[1])+1<<endl;continue;}
for(int i=1;i<=n;i++)
{
ans+=pow(a[i],b[i]);
//cout<<c[i]<<endl;
//cout<<total<<endl;
}
//cout<<"total:"<<total<<endl;
cout<<"Case "<<id++<<": "<<ans<<endl;
}
}
上一篇: JNI 简单使用 (二)
下一篇: java堆排序思想及代码实现
推荐阅读
-
团体队列 UVA540 Team Queue
-
丑数(Ugly Numbers, UVa 136)
-
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
-
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
-
唯一的雪花(Unique snowflakes,UVa 11572)滑动窗口+set
-
[UVA - 11584] Partitioning by Palindromes dp预处理
-
UVA227-Puzzle
-
UVA 442 Matrix Chain Multiplication ( stack 应用)
-
UVA 136 - Ugly Numbers(优先队列 + 集合)
-
(UVa 136) Ugly Numbers(丑数的生成+整数分解定理+优先队列)