#include<bits/stdc++.h>
using namespace std;
#define N 100000
bool status[N+1];
vector<int>primes;
//can store upto 664578 primes
void seive(){
int i,j,total=1,len;
primes.push_back(2);
len=sqrt(N);
for(i=3;i<=len;i+=2){
if(!status[i]){
for(j=i*i;j<=N;j+=i)status[j]=true;
}
}
for(i=3;i<=N;i+=2){
if(!status[i]){
primes.push_back(i);
total++;
}
}
//return total;
}
vector<int>numPF(int n){
vector<int>facts;
int pf_idx=0,pf=primes[pf_idx],ans=0;
while(pf*pf<=n){
if(n%pf==0){
facts.push_back(pf);
while(n%pf==0)n/=pf;
}
pf=primes[++pf_idx];
}
if(n!=1)facts.push_back(n);
return facts;
}
pair<int,int>sqrechk(int x){
int a,b;
a=0,b=x;
while(a<=b){
if(a*a+b*b==x)return make_pair(a,b);
else if(a*a+b*b>x)b--;
else a++;
}
return make_pair(-1,-1);
}
typedef pair<int,int> ii;
int main(){
seive();
int n,i,sz,cases=0;
while(scanf("%d",&n)!=EOF){
vector<int>facts;
facts=numPF(n);
sz=facts.size();
vector<ii>ans;
printf("Case #%d: ",++cases);
//for(i=0;i<facts.size();i++)cout<<facts[i]<<" ";
if(sz==0)printf("\n");
else{
for(i=0;i<sz;i++){
if(facts[i]%4==3)ans.push_back(ii(facts[i],0));
else ans.push_back(sqrechk(facts[i]));
}
sz=ans.size();
for(i=0;i<sz-1;i++){
if(ans[i].second==0)printf("%d, ",ans[i].first);
else if(ans[i].second==1)printf("%d+j, %d-j, ",ans[i].first,ans[i].first);
else printf("%d+%dj, %d-%dj, ",ans[i].first,ans[i].second,ans[i].first,ans[i].second);
}
if(ans[sz-1].second==0)printf("%d\n",ans[sz-1].first);
else if(ans[sz-1].second==1)printf("%d+j, %d-j\n",ans[sz-1].first,ans[sz-1].first);
else printf("%d+%dj, %d-%dj\n",ans[sz-1].first,ans[sz-1].second,ans[sz-1].first,ans[sz-1].second);
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBOIDEwMDAwMApib29sIHN0YXR1c1tOKzFdOwp2ZWN0b3I8aW50PnByaW1lczsKLy9jYW4gc3RvcmUgdXB0byA2NjQ1NzggcHJpbWVzCnZvaWQgc2VpdmUoKXsKICAgIGludCBpLGosdG90YWw9MSxsZW47CiAgICBwcmltZXMucHVzaF9iYWNrKDIpOwogICAgbGVuPXNxcnQoTik7CiAgICBmb3IoaT0zO2k8PWxlbjtpKz0yKXsKICAgICAgICBpZighc3RhdHVzW2ldKXsKICAgICAgICAgICAgZm9yKGo9aSppO2o8PU47ais9aSlzdGF0dXNbal09dHJ1ZTsKICAgICAgICB9CiAgICB9CiAgICBmb3IoaT0zO2k8PU47aSs9Mil7CiAgICAgICAgaWYoIXN0YXR1c1tpXSl7CiAgICAgICAgICAgIHByaW1lcy5wdXNoX2JhY2soaSk7CiAgICAgICAgICAgIHRvdGFsKys7CiAgICAgICAgfQogICAgfQogICAgLy9yZXR1cm4gdG90YWw7Cn0KdmVjdG9yPGludD5udW1QRihpbnQgbil7CiAgICB2ZWN0b3I8aW50PmZhY3RzOwogICAgaW50IHBmX2lkeD0wLHBmPXByaW1lc1twZl9pZHhdLGFucz0wOwogICAgd2hpbGUocGYqcGY8PW4pewogICAgICAgIGlmKG4lcGY9PTApewogICAgICAgICAgICBmYWN0cy5wdXNoX2JhY2socGYpOwogICAgICAgICAgICB3aGlsZShuJXBmPT0wKW4vPXBmOwogICAgICAgIH0KICAgICAgICBwZj1wcmltZXNbKytwZl9pZHhdOwogICAgfQogICAgaWYobiE9MSlmYWN0cy5wdXNoX2JhY2sobik7CiAgICByZXR1cm4gZmFjdHM7Cn0KcGFpcjxpbnQsaW50PnNxcmVjaGsoaW50IHgpewogICAgaW50IGEsYjsKICAgIGE9MCxiPXg7CiAgICB3aGlsZShhPD1iKXsKICAgICAgICBpZihhKmErYipiPT14KXJldHVybiBtYWtlX3BhaXIoYSxiKTsKICAgICAgICBlbHNlIGlmKGEqYStiKmI+eCliLS07CiAgICAgICAgZWxzZSBhKys7CiAgICB9CiAgICByZXR1cm4gbWFrZV9wYWlyKC0xLC0xKTsKfQp0eXBlZGVmIHBhaXI8aW50LGludD4gaWk7CmludCBtYWluKCl7CiAgICBzZWl2ZSgpOwogICAgaW50IG4saSxzeixjYXNlcz0wOwogICAgd2hpbGUoc2NhbmYoIiVkIiwmbikhPUVPRil7CiAgICAgICAgdmVjdG9yPGludD5mYWN0czsKICAgICAgICBmYWN0cz1udW1QRihuKTsKICAgICAgICBzej1mYWN0cy5zaXplKCk7CiAgICAgICAgdmVjdG9yPGlpPmFuczsKICAgICAgICBwcmludGYoIkNhc2UgIyVkOiAiLCsrY2FzZXMpOwogICAgICAgIC8vZm9yKGk9MDtpPGZhY3RzLnNpemUoKTtpKyspY291dDw8ZmFjdHNbaV08PCIgIjsKICAgICAgICBpZihzej09MClwcmludGYoIlxuIik7CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgZm9yKGk9MDtpPHN6O2krKyl7CiAgICAgICAgICAgICAgICBpZihmYWN0c1tpXSU0PT0zKWFucy5wdXNoX2JhY2soaWkoZmFjdHNbaV0sMCkpOwogICAgICAgICAgICAgICAgZWxzZSBhbnMucHVzaF9iYWNrKHNxcmVjaGsoZmFjdHNbaV0pKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzej1hbnMuc2l6ZSgpOwogICAgICAgICAgICBmb3IoaT0wO2k8c3otMTtpKyspewogICAgICAgICAgICAgICAgaWYoYW5zW2ldLnNlY29uZD09MClwcmludGYoIiVkLCAiLGFuc1tpXS5maXJzdCk7CiAgICAgICAgICAgICAgICBlbHNlIGlmKGFuc1tpXS5zZWNvbmQ9PTEpcHJpbnRmKCIlZCtqLCAlZC1qLCAiLGFuc1tpXS5maXJzdCxhbnNbaV0uZmlyc3QpOwogICAgICAgICAgICAgICAgZWxzZSBwcmludGYoIiVkKyVkaiwgJWQtJWRqLCAiLGFuc1tpXS5maXJzdCxhbnNbaV0uc2Vjb25kLGFuc1tpXS5maXJzdCxhbnNbaV0uc2Vjb25kKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihhbnNbc3otMV0uc2Vjb25kPT0wKXByaW50ZigiJWRcbiIsYW5zW3N6LTFdLmZpcnN0KTsKICAgICAgICAgICAgZWxzZSBpZihhbnNbc3otMV0uc2Vjb25kPT0xKXByaW50ZigiJWQraiwgJWQtalxuIixhbnNbc3otMV0uZmlyc3QsYW5zW3N6LTFdLmZpcnN0KTsKICAgICAgICAgICAgZWxzZSBwcmludGYoIiVkKyVkaiwgJWQtJWRqXG4iLGFuc1tzei0xXS5maXJzdCxhbnNbc3otMV0uc2Vjb25kLGFuc1tzei0xXS5maXJzdCxhbnNbc3otMV0uc2Vjb25kKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQoK