UVA 897 Anagrammatic Primes Solution
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
int n,i,t,j,a,c,f,ar[1000];
int ag[] = {2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97, 113, 131, 199, 311, 337, 373, 733, 919, 991};
while(cin>>n)
{
if(n==0)
break;
c=0,f=0;
if(n>=991)
cout<<"0"<<endl;
if(n<10)
{
for(i=n+1; i<10; i++)
{
for(int j=0; j<22; j++)
{
if(ag[j]==i)
{
cout<<ag[j]<<endl;
f=1;
break;
}
if(f==1)
break;
}
if(f==1)
break;
}
if(f==0)
cout<<"0"<<endl;
}
else if(n<100)
{
for(i=n+1; i<100; i++)
{
for(int j=0; j<22; j++)
{
if(ag[j]==i)
{
cout<<ag[j]<<endl;
f=1;
break;
}
if(f==1)
break;
}
if(f==1)
break;
}
if(f==0)
cout<<"0"<<endl;
}
else
{
for(i=n+1; i<=n*10; i++)
{
for(int j=0; j<22; j++)
{
if(ag[j]==i)
{
cout<<ag[j]<<endl;
f=1;
break;
}
if(f==1)
break;
}
if(f==1)
break;
}
}
}
}
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
using namespace std;
int main()
{
int n,i,t,j,a,c,f,ar[1000];
int ag[] = {2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97, 113, 131, 199, 311, 337, 373, 733, 919, 991};
while(cin>>n)
{
if(n==0)
break;
c=0,f=0;
if(n>=991)
cout<<"0"<<endl;
if(n<10)
{
for(i=n+1; i<10; i++)
{
for(int j=0; j<22; j++)
{
if(ag[j]==i)
{
cout<<ag[j]<<endl;
f=1;
break;
}
if(f==1)
break;
}
if(f==1)
break;
}
if(f==0)
cout<<"0"<<endl;
}
else if(n<100)
{
for(i=n+1; i<100; i++)
{
for(int j=0; j<22; j++)
{
if(ag[j]==i)
{
cout<<ag[j]<<endl;
f=1;
break;
}
if(f==1)
break;
}
if(f==1)
break;
}
if(f==0)
cout<<"0"<<endl;
}
else
{
for(i=n+1; i<=n*10; i++)
{
for(int j=0; j<22; j++)
{
if(ag[j]==i)
{
cout<<ag[j]<<endl;
f=1;
break;
}
if(f==1)
break;
}
if(f==1)
break;
}
}
}
}
No comments