Prime frequency

Analysis of Prime frequency(Problem 10789)

#include
#include
#include
int p[2003]; //global array of storing prime number
int crossout(int p[],int n, int i) //function definition to cross out the multipl of i(i=1..n)
{
int k;
for(k=i+1;k<=n;k++)
{
if(p[k]%i==0)//if we find any multiple of i just change the value of that position by 1.
p[k]=1;
}
}

main()
{
int i,j,n,temp,length;
for(i=1;i<=2001;i++) //store 1 to 2001 in a global array
{
p[i]=i;
}
for(i=2;i<=sqrt(2001);i++) // apply sieve method to find out prime numbers
{
//if we find 1 in array position p[i] we do not need to cross-out.(that means it is already crossed out.
if(p[i]!=1)
crossout(p,2001,i);
}
scanf(“%d”,&n);
int Testcase=0;
while(n–)
{
int count=0,primecount=0;
char a[2001]={‘\0’},b[65]; //initialise NULL to each position of the array.
int c[125]={0}; //initialise 0 to each position of the array.
scanf(“%s”,a);
length=strlen(a); //measure the length of the string
for(i=0;i=b[j+1])
{
temp=b[j+1];
b[j+1]=b[j];
b[j]=temp;
}
}
}
printf(“Case %d: “,++Testcase); //print the case no.
for(i=1;i<=count;i++)
{
j=c[b[i]];
// just print the character which one is entered prime number times from b array
if(p[j]!=1)
{
printf(“%c”,b[i]);
primecount++;
}
}
//if there r no character which one is entered primenumber times from b array just print empty
if(primecount==0)
{
printf(“empty”);
}
printf(“\n”);
primecount=0;
}

}

Leave a Comment

Scroll to Top