রবিবার, ২৮ আগস্ট, ২০১৬

UVA 406 - Prime Cuts

#include<stdio.h>
#include<math.h>
main()
{
long int n,a;
while(scanf("%ld%ld",&n,&a)!=EOF)
{
long int i,j;
long int p=sqrt(n),b[10000]={0},c[10000]={0},count=0,k=2,s,count1=1;
b[1]=1;
for(i=2;i<=n;i++)
{
count=1;
for(j=2;j<=sqrt(i);j++)
{
if(i%j==0)
  {
count=0;
break;
  }
}

if(count==1)
{
b[k++]=i;
count1++;
}
count=0;
}
/*printf("%ld\n",k-1);
for(long int k1=1;k1<k;k1++)
{
printf("%ld ",b[k1]);
}*/
long int count2=count1;
printf("%ld %ld:",n,a);
if(count1%2==0)
{
a=a*2;
count1=count1-a;
}
else
{
a=a*2-1;
count1=count1-a;
}
count1=count1/2;
//printf("%ld",count1);
if(count1>=0)
{
for(long int j1=count1+1;j1<=count2-count1;j1++)
{
printf(" %ld",b[j1]);
}
   }
else
{
for(long int j1=1;j1<=count2;j1++)
{
printf(" %ld",b[j1]);
}
}
printf("\n\n");

}


}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factory Pattern

Factory Method  is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...