Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:11:42+00:00 2026-05-27T10:11:42+00:00

Here’s the problem statement: The number 3797 has an interesting property. Being prime itself,

  • 0

Here’s the problem statement:

The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.

Find the sum of the only eleven primes that are both truncatable from left to right and right to left.

NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.

My code gives me a partial output. Only 5 or 6 of the eleven required primes are being outputted, 3797 not being one of them. So to find the error, I manually (on a piece of paper) ran the code for 3797 and somehow can’t manage to find the glitch.

I think the error is in the second part, the part of code which checks whether the number is truncatable from the left.

Code:

#include<stdio.h>
      int isprime(int n) //Checks whether the number is prime or not
      {
        int i;
        if(n==1)
        return(0);
        for(i=2;i<n/2+1;i++)
        {

            if(n%i==0)
            {
                return(0);
                break;
            }   
        }
        return(1);      
      }
      int main(void)
      {
        int count=0,z=0;
        int i;
        int n;
        int x=1;
        int reverse2=0;
        int z1=0;
        int p;
        int count1=0;
        int digit;
        int k=1000000;
        int reverse=0;
        for(i=2;i<k;i++)
        {
            if(isprime(i)==1)
            {
                n=i;
                p=i;
                while(n>0) // This function removes the digits of the prime number from the right
                {
                    n=n/10;
                    if(isprime(n)==1)
                    {
                        count++;
                    }   
                    z++;
                }

                if(z==count) 
                {   
                        while(p>0) //Checks whether number is left truncatable 
                        {   
                            digit=p%10;
                            p=p/10;
                                if(z1==0)
                                {
                                    reverse=digit;//here reverse doesn't refer to reversing the number. It builds the number one digit at a time from right to left.
                                }
                                else
                                {   
                                    reverse=digit*x*10+reverse;
                                    x++;
                                }
                                if(isprime(reverse)==1)
                                {
                                    count1++;
                                }
                            z1++;

                        }

                        if(z1==count1)
                        printf("%d ",i);

                }
                    z=0;
                    z1=0;
                    count1=0;
                    count=0;
                    reverse=0;
                    reverse2=0;
                    x=1;
            }                                                                                                                                                                                       
        }   

      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:11:42+00:00Added an answer on May 27, 2026 at 10:11 am

    Your left truncatable check is wrong. I did it differently, simpler.

    #include<stdio.h>
    int isprime(int n) //Checks whether the number is prime or not
    {
        int i;
        if(n==1)
            return(0);
        for(i=2;i<n/2+1;i++)
        {
    
            if(n%i==0)
            {
                return(0);
                break;
            }   
        }
        return(1);      
    }
    int power(int a, int b){
        int r = 1;
        int i=0;
        for (i=0;i<b;i++){
            r = r * a;
        }
        return r;
    }
    
    int main(void)
    {
        int count=0,z=0;
        int i;
        int n;
        int z1=0;
        int p;
        int count1=0;
        int digits;
        int k=1000000;
        for(i=2;i<k;i++)
        {
            if(isprime(i)==1)
            {
                z = 0;
                count = 0;
                n=i;
                p=i;
                while(n>0) // This function removes the digits of the prime number from the right
                {
                    n=n/10;
                    if(isprime(n)==1)
                    {
                        count++;
                    }else{
                        count = -1;
                        break;
                    }   
                    z++;
                }
    
                if(z==count) 
                {   
                    z1= 0;
                    count1=0;
                    n = i;
                    p= i;
                    while(p>0) //Checks whether number is left truncatable 
                    {   
                        digits=n%power(10,z1+1);
                        p = p /10;
                        if (isprime(digits)==1)
                        {
                            count1++; 
                        }else{
                            count1 =-1;
                            break;
                        }
                        z1++;
                    }
    
                    if(z1==count1)
                        printf("%d\n ",i);
    
                }
            }                                                                                                                                                                                       
        }   
    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here is another spoj problem that asks how to find the number of distinct
Here's a problem I ran into recently. I have attributes strings of the form
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's a coding problem for those that like this kind of thing. Let's see
Here is my problem : I have a post controller with the action create.
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here's the problem....I have three components...A Page that contains a User Control and a
Here is my problem...I have a page that loads a list of clients and
Here is an example: I have a file 1.js, which has some functions. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.