MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Sunday, March 3, 2013

uva solve problem id 897 - Anagrammatic Primes l

#include<stdio.h>
#include<math.h>
long int a[10000005],b[10000005],c[10000005];
 int main()
{
    int i,j,k,l,t,p;
    for(i=0;i<10000004;i=i+1)
    a[i]=0;
    p=sqrt(10000000);
    for(j=2;j<p;j=j+1)
    {
        for(k=2;k*j<10000001;k=k+1)
        a[k*j]=1;
    }
    a[0]=1;
    a[1]=1;
    long int n,sum,h,m,v;
    while(scanf("%ld",&n)!=EOF)
    {
        if(n==0)
        break;
        for(i=n+1;;i++)
        {
            v=i;
            for(k=0;;k++)
            {
             c[k]=i%10;
             i/=10;
             if(i==0)
             break;
            }
            h=0;
            sum=0;
            for(m=k;m>=0;m--)
            {
            sum=sum+c[m]*pow(10,h);
            h++;
            }
            if(a[sum]==0)
            {
            printf("%ld\n",v);
            break;
            }
        }
    }
    return 0;
}

No comments:

Post a Comment