10235 - Simply Emirp

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: simply emrip 10235

Post by brianfry713 » Tue Nov 05, 2013 9:24 pm

An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.
Check input and AC output for thousands of problems on uDebug!

jokerz
New poster
Posts: 8
Joined: Tue Nov 05, 2013 10:24 am

Re: simply emrip 10235

Post by jokerz » Thu Nov 07, 2013 6:49 am

Yeah i know that.i checked my code with different output but i didn't find any mistake..i submitted it but i was getting wa wa ..if u have time kindly run my code and inform me about my fault.....thank you brianfry713

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: simply emrip 10235

Post by brianfry713 » Thu Nov 07, 2013 8:33 pm

727 is prime.
Check input and AC output for thousands of problems on uDebug!

jokerz
New poster
Posts: 8
Joined: Tue Nov 05, 2013 10:24 am

Re: simply emrip 10235

Post by jokerz » Sun Nov 10, 2013 7:03 am

Thnx brianfry713...i have gotten AC :D with the help of your clue...Thnx again..

mujtahid.akon
New poster
Posts: 1
Joined: Sat Nov 16, 2013 9:31 pm

WA in 10235

Post by mujtahid.akon » Sat Nov 16, 2013 9:48 pm

here is my code.
why am i getting WA???
please help ..

http://pastebin.com/X1vPYQJs

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: WA in 10235

Post by brianfry713 » Mon Nov 18, 2013 10:42 pm

Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: simply emrip 10235

Post by uDebug » Sat Apr 12, 2014 2:33 pm

brianfry713 wrote:An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.
Phew! Thanks so much for this and for the test case. I totally missed this while reading the problem statement.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: simply emrip 10235

Post by uDebug » Sat Apr 12, 2014 2:34 pm

Here's some input / output I found useful during testing / debugging.

Input:

Code: Select all

999
481184
373
998001
998857
753257
823455
999999
850058
78887
999983
AC Output:

Code: Select all

999 is not prime.
481184 is not prime.
373 is prime.
998001 is not prime.
998857 is emirp.
753257 is prime.
823455 is not prime.
999999 is not prime.
850058 is not prime.
78887 is prime.
999983 is emirp.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

woaraka92
New poster
Posts: 9
Joined: Sun Oct 20, 2013 6:50 pm

simply emrip 10235

Post by woaraka92 » Tue Jul 22, 2014 9:27 pm

whats wrong with this code??

#include<stdio.h>
#include<math.h>

int prime(long int n)
{
long int i;
if(n==0)
return 0;
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return 0;
}
return 1;
}


long int rev(long int n)
{
long int s=0;
while(n!=0)
{
s=s*10+n%10;
n/=10;
}
return s;
}


int main()
{
long int n,r;
while(scanf("%ld",&n)==1)
{
if(prime(n)==0)
printf("%ld is not prime.\n",n);
else
{
r=rev(n);
if(prime(r)==0)
printf("%ld is prime.\n",n);
else
printf("%ld is emirp.\n",n);
}
}
return 0;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: simply emrip 10235

Post by lighted » Tue Jul 22, 2014 10:11 pm

An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed
So must check if r not equal to n to be "emirp"

Code: Select all

if(prime(r)==0 || r == n)
 printf("%ld is prime.\n",n);
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

ashek.rahman
New poster
Posts: 8
Joined: Mon Mar 10, 2014 8:18 am

Re: 10235 - Simply Emirp

Post by ashek.rahman » Thu Oct 23, 2014 10:54 am

Accepted :) Removed :)
Thanks for your help :)
Last edited by ashek.rahman on Fri Oct 24, 2014 6:50 am, edited 2 times in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10235 - Simply Emirp

Post by lighted » Thu Oct 23, 2014 3:58 pm

Your code doesn't pass all tests posted in this thread.
brianfry713 wrote:101 is prime, not emirp, it has to be a different prime after reversal.
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

DarkknightRHZ
New poster
Posts: 2
Joined: Mon Aug 31, 2015 11:19 pm

Re: 10235 - Simply Emirp

Post by DarkknightRHZ » Mon Aug 31, 2015 11:24 pm

Hi, can anyone please help me with this code. I have checked everything but still wrong answer!

Code: Select all

#include <bits/stdc++.h>

using namespace std;

#define PB          push_back
#define PF          push_front
#define  V          vector
#define PII         pair <int,int>
#define MII         map <int,int>
#define MSI         map <string,int>
#define MIS         map <int,string>
#define MLI         map <long long int,int>
#define MIL         map <int,long long int>
typedef long long int           LL;
typedef int                     I;
typedef double                  D;
typedef float                   F;
typedef bool                    B;
typedef char                    C;
typedef string                  S;
typedef vector <string>         VS;
typedef vector <int>            VI;
typedef vector <char>           VC;

/* Functions */

I GCD (I x, I y){if (x%y==0) return y; else return (GCD(y,x%y));}
I prime[1002002]={0};
void init(void)
{
    I i,j;
    prime[0]=1;
    for (i=4;i<1002002;i+=2)
    {
        prime[i]=1;
    }
    for (i=3;i<=1001;i+=2)
    {
        for (j=i*i;j<1002002;j+=(i+i))
        {
            prime[j]=1;
        }
    }

}

int main()
{
    #ifdef DKRHZ
        freopen("get.txt","r",stdin);
        //freopen("got.txt","w",stdout);
    #endif // DKRHZ
    init();
    bool p,e;
    I x,n,cns;
    while (scanf("%d",&n)==1)
    {
        x=n;
        p=e=false;
        if (!prime[n])
            p=true;
        cns=0;
        while (n>0)
        {
            cns*=10;
            cns+=n%10;
            n/=10;
        }
        if (!prime[cns] && cns!=x)
        {
            e=true;
        }
        if (!p && !e)
        {
            printf("%d is not prime.\n",x);
        }
        else if (p && e)
        {
            printf("%d is emirp.\n",x);
        }
        else if (p && !e)
        {
            printf("%d is prime.\n",x);
        }
    }
    return 0;
}
Last edited by brianfry713 on Tue Sep 08, 2015 1:08 am, edited 1 time in total.
Reason: Added code block

DarkknightRHZ
New poster
Posts: 2
Joined: Mon Aug 31, 2015 11:19 pm

Re: 10235 - Simply Emirp

Post by DarkknightRHZ » Mon Aug 31, 2015 11:24 pm

Hi, can anyone please help me with this code. I have checked everything but still wrong answer!

Code: Select all

#include <bits/stdc++.h>

using namespace std;

#define PB          push_back
#define PF          push_front
#define  V          vector
#define PII         pair <int,int>
#define MII         map <int,int>
#define MSI         map <string,int>
#define MIS         map <int,string>
#define MLI         map <long long int,int>
#define MIL         map <int,long long int>
typedef long long int           LL;
typedef int                     I;
typedef double                  D;
typedef float                   F;
typedef bool                    B;
typedef char                    C;
typedef string                  S;
typedef vector <string>         VS;
typedef vector <int>            VI;
typedef vector <char>           VC;

/* Functions */

I GCD (I x, I y){if (x%y==0) return y; else return (GCD(y,x%y));}
I prime[1002002]={0};
void init(void)
{
    I i,j;
    prime[0]=1;
    for (i=4;i<1002002;i+=2)
    {
        prime[i]=1;
    }
    for (i=3;i<=1001;i+=2)
    {
        for (j=i*i;j<1002002;j+=(i+i))
        {
            prime[j]=1;
        }
    }

}

int main()
{
    #ifdef DKRHZ
        freopen("get.txt","r",stdin);
        //freopen("got.txt","w",stdout);
    #endif // DKRHZ
    init();
    bool p,e;
    I x,n,cns;
    while (scanf("%d",&n)==1)
    {
        x=n;
        p=e=false;
        if (!prime[n])
            p=true;
        cns=0;
        while (n>0)
        {
            cns*=10;
            cns+=n%10;
            n/=10;
        }
        if (!prime[cns] && cns!=x)
        {
            e=true;
        }
        if (!p && !e)
        {
            printf("%d is not prime.\n",x);
        }
        else if (p && e)
        {
            printf("%d is emirp.\n",x);
        }
        else if (p && !e)
        {
            printf("%d is prime.\n",x);
        }
    }
    return 0;
}
Last edited by brianfry713 on Tue Sep 08, 2015 1:07 am, edited 1 time in total.
Reason: Added code block

SHUVOJITKAR
New poster
Posts: 2
Joined: Tue Jun 28, 2016 12:13 pm

Re: 10235 - Simply Emirp

Post by SHUVOJITKAR » Tue Jun 28, 2016 12:18 pm

why i get runtime error?

import java.util.Scanner;

public class uv2a10235 {

static int Rev(int n){
int x=n;
int k,j=0;
while(x!=0){
k=x%10;
j=j*10+k;
x/=10;
}
return j;

}
static boolean isPrime(int n){
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0){
return false;
}
}
return true;
}
private static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
while(in.hasNext()){
int n = in.nextInt();
int m = Rev(n);
if(isPrime(n)==true){


if(n!=m && n>9 && isPrime(m)==true){

System.out.println(n + " is emirp.");
}else {

System.out.println(n + " is prime.");
}
}
else{

System.out.println(n + " is not prime.");
}


}

}
}

Post Reply

Return to “Volume 102 (10200-10299)”