Page 10 of 11

Re: simply emrip 10235

Posted: Tue Nov 05, 2013 9:24 pm
by brianfry713
An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.

Re: simply emrip 10235

Posted: Thu Nov 07, 2013 6:49 am
by jokerz
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

Re: simply emrip 10235

Posted: Thu Nov 07, 2013 8:33 pm
by brianfry713
727 is prime.

Re: simply emrip 10235

Posted: Sun Nov 10, 2013 7:03 am
by jokerz
Thnx brianfry713...i have gotten AC :D with the help of your clue...Thnx again..

WA in 10235

Posted: Sat Nov 16, 2013 9:48 pm
by mujtahid.akon
here is my code.
why am i getting WA???
please help ..

http://pastebin.com/X1vPYQJs

Re: WA in 10235

Posted: Mon Nov 18, 2013 10:42 pm
by brianfry713

Re: simply emrip 10235

Posted: Sat Apr 12, 2014 2:33 pm
by uDebug
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.

Re: simply emrip 10235

Posted: Sat Apr 12, 2014 2:34 pm
by uDebug
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.

simply emrip 10235

Posted: Tue Jul 22, 2014 9:27 pm
by woaraka92
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;
}

Re: simply emrip 10235

Posted: Tue Jul 22, 2014 10:11 pm
by lighted
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)

Re: 10235 - Simply Emirp

Posted: Thu Oct 23, 2014 10:54 am
by ashek.rahman
Accepted :) Removed :)
Thanks for your help :)

Re: 10235 - Simply Emirp

Posted: Thu Oct 23, 2014 3:58 pm
by lighted
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)

Re: 10235 - Simply Emirp

Posted: Mon Aug 31, 2015 11:24 pm
by DarkknightRHZ
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;
}

Re: 10235 - Simply Emirp

Posted: Mon Aug 31, 2015 11:24 pm
by DarkknightRHZ
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;
}

Re: 10235 - Simply Emirp

Posted: Tue Jun 28, 2016 12:18 pm
by SHUVOJITKAR
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.");
}


}

}
}