897  Anagrammatic Primes
Moderator: Board moderators
897  Anagrammatic Primes
What changed after rejudge? Is there any anaglemtic primes after 991? What are the traps?

 Learning poster
 Posts: 58
 Joined: Wed Dec 31, 2003 8:43 am
 Location: Dhaka, Bangladesh
 Contact:
Re: 897 WA
no , there is no ana. prime after 991. There are only 22 ana. primes.abc wrote:What changed after rejudge? Is there any anaglemtic primes after 991? What are the traps?
i think there is no trips in this problem. Just do what's the problem say.
how do you consider the case "You must find the first anagrammatic prime which is larger than n and less than the next power of 10 greater than n." ???
L I M O N
Last edited by L I M O N on Tue Jul 20, 2004 9:32 am, edited 1 time in total.
We can know that from n > 10, if n is a ana.prime ,
the digits of n can only contain 1, 3, 7, 9.
(since even number & 5 obviously cant be ana.prime)
But, does anyone know why numbers bigger than 1000
with digits of 1, 3, 7, 9 can't be ana. prime?
(or just by this program result?)
I try to find it , but failed.
the digits of n can only contain 1, 3, 7, 9.
(since even number & 5 obviously cant be ana.prime)
But, does anyone know why numbers bigger than 1000
with digits of 1, 3, 7, 9 can't be ana. prime?
(or just by this program result?)
I try to find it , but failed.

 Learning poster
 Posts: 58
 Joined: Wed Dec 31, 2003 8:43 am
 Location: Dhaka, Bangladesh
 Contact:
9 isn't a prime number.InOutMoTo wrote:We can know that from n > 10, if n is a ana.prime ,
the digits of n can only contain 1, 3, 7, 9.
(since even number & 5 obviously cant be ana.prime)
But, does anyone know why numbers bigger than 1000
with digits of 1, 3, 7, 9 can't be ana. prime?
(or just by this program result?)
how do you sure that there is no ana. prime after 1000 ???
L I M O N
Well there ARE bigger anagrammatic primes!!!
http://www.research.att.com/cgibin/acc ... num=004023
From this we know that 1111111111111111111 is also an anagrammatic prime @_@
http://www.research.att.com/cgibin/acc ... num=004023
From this we know that 1111111111111111111 is also an anagrammatic prime @_@
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
only 22 anagramatic primes IN THE RANGE ...
they are :
0>10

1. 2
2. 3
3. 5
4. 7
10>100

5. 11
6. 13
7. 17
8. 31
9. 37
10. 71
11. 73
12. 79
13. 97
100>1000

14. 113
15. 131
16. 199
17. 311
18. 337
19. 373
20. 733
21. 919
22. 991
if input is greater than 991 , ans would be 0.
precalculation makes it an easy problem .
they are :
0>10

1. 2
2. 3
3. 5
4. 7
10>100

5. 11
6. 13
7. 17
8. 31
9. 37
10. 71
11. 73
12. 79
13. 97
100>1000

14. 113
15. 131
16. 199
17. 311
18. 337
19. 373
20. 733
21. 919
22. 991
if input is greater than 991 , ans would be 0.
precalculation makes it an easy problem .
Syed Ishtiaque Ahmed Kallol
CSE,BUET
Bangladesh
CSE,BUET
Bangladesh
897 WA Anagrammatic Primes
Hello everyone!
I am getting WA with this code Could someone plz give me a hint.
From the previous post I understood that anagrammatic primes are only in the range from 1 to 1000. Is that right?
However, here is my code:
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
bool is_prime(long long int result)
{
bool prime = true;
for(long long int i = 2;prime and i*i<=result; i++)
{
if(result%i==0)
prime = false;
}
return prime;
}
string to_string(long long int n)
{
string result="";
while(n/10!=0)
{
result+=(n%10) + '0';
n/=10;
}
result+=(n%10)+'0';
return result;
}
string reverse(string num)
{
string result="";
for(int i=num.size()1; i>=0; i)
result+=num;
return result;
}
long long int to_int(string num)
{
long long int result = 0;
int times = 1;
for(int i = num.size()1; i>=0; i)
{
result+=(num'0')*times;
times*=10;
}
return result;
}
bool check(string num)
{
bool result = true ;
long long int number = to_int(num);
result = is_prime(number);
for(int i = 0; i<num.size(); i++)
{
for(int j=1; result and j<num.size(); j++)
{
swap(num[j1], num[j]);
number = to_int(num);
result = is_prime(number);
if(result==false)
goto stop;
}
}
stop:
return result;
}
int main()
{
long long int array[50];
array[0]=2; array[1]=3; array[2]=5; array[3]=7;
int a =4;
for(long long int i = 10; i<=1000; i++)
{
string string_num = to_string(i);
bool ok = check(string_num);
if(ok)
{
array[a]=i;
a++;
}
}
long long number;
while(cin>>number and number !=0)
{
if(number>1000)
cout<<0<<endl;
string broj = to_string(number);
double len = broj.size();
long long int power = static_cast<long long int>(pow(10, len));
bool go = true;
for(int g=0; go and g<a; g++)
{
if(array[g]>number and array[g]<power)
{
cout<<array[g]<<endl;
go = false;
}
}
}
}
Thanx!
I am getting WA with this code Could someone plz give me a hint.
From the previous post I understood that anagrammatic primes are only in the range from 1 to 1000. Is that right?
However, here is my code:
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
using namespace std;
bool is_prime(long long int result)
{
bool prime = true;
for(long long int i = 2;prime and i*i<=result; i++)
{
if(result%i==0)
prime = false;
}
return prime;
}
string to_string(long long int n)
{
string result="";
while(n/10!=0)
{
result+=(n%10) + '0';
n/=10;
}
result+=(n%10)+'0';
return result;
}
string reverse(string num)
{
string result="";
for(int i=num.size()1; i>=0; i)
result+=num;
return result;
}
long long int to_int(string num)
{
long long int result = 0;
int times = 1;
for(int i = num.size()1; i>=0; i)
{
result+=(num'0')*times;
times*=10;
}
return result;
}
bool check(string num)
{
bool result = true ;
long long int number = to_int(num);
result = is_prime(number);
for(int i = 0; i<num.size(); i++)
{
for(int j=1; result and j<num.size(); j++)
{
swap(num[j1], num[j]);
number = to_int(num);
result = is_prime(number);
if(result==false)
goto stop;
}
}
stop:
return result;
}
int main()
{
long long int array[50];
array[0]=2; array[1]=3; array[2]=5; array[3]=7;
int a =4;
for(long long int i = 10; i<=1000; i++)
{
string string_num = to_string(i);
bool ok = check(string_num);
if(ok)
{
array[a]=i;
a++;
}
}
long long number;
while(cin>>number and number !=0)
{
if(number>1000)
cout<<0<<endl;
string broj = to_string(number);
double len = broj.size();
long long int power = static_cast<long long int>(pow(10, len));
bool go = true;
for(int g=0; go and g<a; g++)
{
if(array[g]>number and array[g]<power)
{
cout<<array[g]<<endl;
go = false;
}
}
}
}
Thanx!

 New poster
 Posts: 13
 Joined: Wed Oct 26, 2005 10:14 pm
 Location: Iran
 Contact: