#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
using namespace std;
#define max(a,b) (a>b?a:b)
bitset<1001> p;
vector<int> prime;
void calc(){
int tmp=1000;
int tmp2=32;
for(int i=2;i<=tmp;i++){
if(!p[i]){
prime.push_back(i);
if(i<=tmp2)
for(int j=i*i;j<=tmp;j+=i)
p[j]=1;
}
}
}
int pw(int x,int y){
int ans=1;
while(y){
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
vector<int> sum(1001,-1);
int main(){
calc();
ios::sync_with_stdio(0);
sum[1]=1;
for(int i=2;i<1001;i++){
int tmp=i,sm=1;
for(int j=0;j<prime.size()&&prime[j]<=tmp;j++){
if(tmp%prime[j]==0){
int ans=0;
while(tmp%prime[j]==0)
tmp/=prime[j],ans++;
sm*=(pw(prime[j],ans+1)-1)/(prime[j]-1);
}
}
if(tmp>1)
sm*=(tmp*tmp-1)/(tmp-1);
if(sm<1001)
sum[sm]=i;
}
int n;
int i=1;
while(cin>>n&&n){
cout<<"Case "<<i++<<": "<<sum[n]<<endl;
}
}
#include <vector>
#include <bitset>
#include <cmath>
using namespace std;
#define max(a,b) (a>b?a:b)
bitset<1001> p;
vector<int> prime;
void calc(){
int tmp=1000;
int tmp2=32;
for(int i=2;i<=tmp;i++){
if(!p[i]){
prime.push_back(i);
if(i<=tmp2)
for(int j=i*i;j<=tmp;j+=i)
p[j]=1;
}
}
}
int pw(int x,int y){
int ans=1;
while(y){
if(y&1)
ans*=x;
x*=x;
y>>=1;
}
return ans;
}
vector<int> sum(1001,-1);
int main(){
calc();
ios::sync_with_stdio(0);
sum[1]=1;
for(int i=2;i<1001;i++){
int tmp=i,sm=1;
for(int j=0;j<prime.size()&&prime[j]<=tmp;j++){
if(tmp%prime[j]==0){
int ans=0;
while(tmp%prime[j]==0)
tmp/=prime[j],ans++;
sm*=(pw(prime[j],ans+1)-1)/(prime[j]-1);
}
}
if(tmp>1)
sm*=(tmp*tmp-1)/(tmp-1);
if(sm<1001)
sum[sm]=i;
}
int n;
int i=1;
while(cin>>n&&n){
cout<<"Case "<<i++<<": "<<sum[n]<<endl;
}
}
Comments
Post a Comment