Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

#INPUT

INPUT

Two integer numbers, first and last are entered.

#OUTPUT

OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

#CONSTRAINTS

CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}
 

Please suggest the possible optimizations.

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

#INPUT

Two integer numbers, first and last are entered.

#OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

#CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}
 

Please suggest the possible optimizations.

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

INPUT

Two integer numbers, first and last are entered.

OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}
 

Please suggest the possible optimizations.

Rollback to Revision 1
Source Link

Find prime Program to find megaPrime numbers in a range whose digits are all primebetween 2 given integers

A number is said to be megaPrime if it is prime, and all its digits are are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

INPUT

Two integer numbers, first and last are entered.

OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

Please suggest possible optimizationsExample:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

#INPUT

Two integer numbers, first and last are entered.

#OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

#CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}

Please suggest the possible optimizations.

Find prime numbers in a range whose digits are all prime

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

INPUT

Two integer numbers, first and last are entered.

OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

Please suggest possible optimizations.

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}

Program to find megaPrime numbers between 2 given integers

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

#INPUT

Two integer numbers, first and last are entered.

#OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

#CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}

Please suggest the possible optimizations.

added 42 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

A number is said to be megaPrime if it is prime, and all its digits are are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

INPUT

Two integer numbers, first and last are entered.

OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

#INPUT

Two integer numbers, first and last are entered.

#OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusivePlease suggest possible optimizations.

#CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}

Please suggest the possible optimizations.

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

#INPUT

Two integer numbers, first and last are entered.

#OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

#CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}

Please suggest the possible optimizations.

A number is said to be megaPrime if it is prime, and all its digits are also prime.

Example:

53 is megaPrime, but 35 is not as it is divisible by 5 and 7. 13 is not a megaPrime number as it contains 1, which is non-prime.

INPUT

Two integer numbers, first and last are entered.

OUTPUT

Display the number of megaPrimes in the inteval between first and last, both inclusive.

CONSTRAINTS

1 <= first <= last <= 10^15

last - first <= 10^9

Please suggest possible optimizations.

/* PROGRAM TO FIND MEGA PRIME NUMBERS BETWEEN TWO GIVEN INTEGERS */
#include<stdio.h>
int isPrime(int);
int isMegaPrime(int);
int main(void)
{
int i=0,st,sp,count=0;
 scanf("%d%d",&st,&sp);
 for(i=st;i<=sp;i++){
 if((i%2)!=0 && isMegaPrime(i)==1)
 count++;
 }
 printf("%d",count);
 return 0;
}
int isPrime(int n)
{
 int i=0,flag=0;
 if(n==1)
 return 0;
 else
 { 
 int t=sqrt(n);
 for(i=2;i<=t;i++){
 if((n%i)==0){
 flag=1;
 break;
 }
 }
 }
 if(flag==1)
 return 0;
 else
 return 1;
}
int isMegaPrime( int n)
{
 int i=0,flag=0,temp=0;
 if(isPrime(n)==0)
 return 0;
 else{
 while (n!=0){
 temp=n%10;
 flag=isPrime(temp);
 if(flag==0)
 return 0;
 n/=10;
 
 }
 }
 if(flag==1)
 return 1;
 else 
 return 0;
}
edited tags; edited title
Link
200_success
  • 145.5k
  • 22
  • 190
  • 478
Loading
Source Link
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /