import java.io.*;
class lucky
{
public static void meth()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter limit");
int n=Integer.parseInt(br.readLine());
int ar[]=new int[n];
for(int i=0;i<n;i++)
ar[i]=i+1;
int a,b,c,d;
a=1;
b=ar.length;
int gap=2;
while(true)
{
for(c=a;c<b;c=c+gap)
{
ar[c]=-1;
}
d=0;
for(c=0;c<b;c++)
{
if(ar[c] != -1)
d++;
}
int temp[]=new int[d];
int p=0;
for(c=0;c<b;c++)
{
if(ar[c] != -1)
temp[p++]=ar[c];
ar[c]=-1;
}
for(c=0;c<p;c++)
{
ar[c]=temp[c];
}
a=a+1;
gap++;
if(a>d)
{
break;
}
}
int res=0;
for(int i=0;i<8;i++)
{
if(ar[i] != -1)
{
int digi=ar[i];
c=0;
while(digi>0)
{
c++;
digi/=10;
}
double t=Math.pow(10,c);
res=(res*(int)t)+ar[i];
}
}
System.out.println(res);
}
}
class lucky
{
public static void meth()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter limit");
int n=Integer.parseInt(br.readLine());
int ar[]=new int[n];
for(int i=0;i<n;i++)
ar[i]=i+1;
int a,b,c,d;
a=1;
b=ar.length;
int gap=2;
while(true)
{
for(c=a;c<b;c=c+gap)
{
ar[c]=-1;
}
d=0;
for(c=0;c<b;c++)
{
if(ar[c] != -1)
d++;
}
int temp[]=new int[d];
int p=0;
for(c=0;c<b;c++)
{
if(ar[c] != -1)
temp[p++]=ar[c];
ar[c]=-1;
}
for(c=0;c<p;c++)
{
ar[c]=temp[c];
}
a=a+1;
gap++;
if(a>d)
{
break;
}
}
int res=0;
for(int i=0;i<8;i++)
{
if(ar[i] != -1)
{
int digi=ar[i];
c=0;
while(digi>0)
{
c++;
digi/=10;
}
double t=Math.pow(10,c);
res=(res*(int)t)+ar[i];
}
}
System.out.println(res);
}
}
No comments:
Post a Comment