// Verdict: Accepted
// Header file begin
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
// End
//..........
// Macros
#define sf scanf
#define pf printf
#define sfint(a,b) scanf("%d %d",&a,&b)
#define sfl(a,b) scanf("%ld %ld",&a,&b)
#define sfll(a,b) scanf("%lld %lld",&a,&b)
#define sfd(a,b) scanf("%lf %lf",&a,&b)
#define sff(a,b) scanf("%f %f",&a,&b)
#define lp1(i,n) for(i=0;i<n;i++)
#define lp2(i,n) for(i=1;i<=n;i++)
#define mem(c,v) memset(c,v,sizeof(c))
#define cp(a) cout<<" "<<a<<" "<<endl
#define nl puts("")
#define sq(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define sz size()
#define gc getchar()
#define pb push_back
// End.........
// Sizes
#define mx7 20000100
#define mx6 1500000
#define mx5 1005
#define inf 1<<30 //infinity value
#define eps 1e-9
#define mx (65540)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;
//..................................................................................................................
typedef long long LL;
typedef long L;
typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> T setbit(T n, T pos){n=n|(1<<pos); return n;}
template<class T> T checkbit(T n, T pos){n=n&(1<<pos); return n;}
template<class T> T gcd(T a, T b ) {return b==0?a:gcd(b,a%b);}
template<class T> T large(T a, T b ) {return a>b?a:b;}
template<class T> T small(T a, T b ) {return a<b?a:b;}
int prime[mx5],prm[(mx5)+1],plen=0;
void seieve(int n)
{
int i,j,x=(int)sqrt(double(n));
prime[0]=setbit(prime[0],0);
prime[0]=setbit(prime[0],1);
for(i=4;i<=n;i+=2)prime[i>>5]=setbit(prime[i>>5],i&31);
for(i=3;i<=x;i+=2)
{
if(!(checkbit(prime[i>>5],i&31)))
{
for(j=i*i;j<=n;j+=i)
{
prime[j>>5]=setbit(prime[j>>5],j&31);
}
}
}
for(i=2;i<=n;i++)
{
if(!checkbit(prime[i>>5],i&31))
{
prm[plen++]=i;
}
}
//lp1(i,plen)cp(prm[i]);
}
LL divisor(LL n)
{
LL i,cnt,m=1;
for(i=0;i<plen and sq(prm[i]) <= n; i++)
{
if(!(n%prm[i]))
{
cnt=1;
while(!(n%prm[i]))
{
cnt++;
n/=prm[i];
if(n==0 or n==1) break;
}
m*=cnt;
}
}
if(n>1)
{
//cnt++;
m*=2;
}
m--;
return m;
}
struct my
{
LL x,y;
};
bool cmp(my a, my b)
{
if(a.y < b.y)
{
return true;
}
else if(a.y == b.y)
{
if(a.x > b.x)
{
return true;
}
}
return false;
}
int main()
{
seieve(1000);
int t,tc=0;
LL i,n;
my ar[1000];
for(i=0;i<1000;i++) // showing garbage i=1 to <=1000
{
ar[i].x=i+1;
ar[i].y=divisor(i+1);
}
//lp1(i,1001)cout << ar[i].x << " " << ar[i].y << endl;
sort(ar,ar+1000,cmp);
//lp1(i,1000)cout << ar[i].x << " " << ar[i].y << endl;
// cin >> n;
// cout << ar[n-1].x << " " << ar[n-1].y << endl;
cin >> t;
while(t--)
{
sf("%lld",&n);
pf("Case %d: %lld\n",++tc,ar[n-1].x);
}
return 0;
}
Comments
Post a Comment