Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Lucky Numbers

Name: Anonymous 2012-02-25 14:36

https://www.interviewstreet.com/challenges/dashboard/#problem/4f15e1bc8f8cd

so the output must be 4 2 for the sample input. i get 2 2 with my code. is there anybody who is dying from boredom and wants to help me? this is the code.

ps. i named number of digits as "bas"

#include<iostream>
using namespace std;

int b(int x)
{
    int bas = 0;
     while (x != 0)
    {
        x = x/10;
        bas++;
    }
    return bas;
}
int digits(int x)
{

    int d = 0;
    int bas = b(x);
    for(int i = 1; i<bas+1;i++)
    {
        d = d +(x%10);
        x = x/10;
    }
       
        int flag=0;
    for(int i = 2; i<d+1; i++)
    {
        if(d%i==0)
        flag=1;
    }
    if(flag == 0)
        return 1;
    else
        return 5;
        }
       
        int squaredigits(int x)
    {
        int d = 0;
    int bas = b(x);
    for(int i = 1; i<bas+1;i++)
    {
        d = d +(x%10)*(x%10);
          x = x/10;
    }
         int flag=0;
    for(int i = 2; i<d+1; i++)
    {
        if(d%i==0)
        flag=1;
    }
    if(flag == 0)
        return 1;
    else
        return 5;
        }
       
int main()
{
    int A,B,T,counter= 0;
    cin>>T;
  
       
    for(int j = 1; j < T +1; j++)
    {
            cin>>A;
            cin>>B;
            for(int k = A; k < B+1;k++)
            {
    if(digits(k)==1 && squaredigits(k) == 1)
        counter++;
       }
       cout<<counter<<endl;

    }

      
      
       return 0;
      }

Name: Anonymous 2012-02-25 14:37

apparently you can't see the question without logging in. ignore the link.

Name: Anonymous 2012-02-25 15:03

>>1

Couldn't you have just paraphrased the question you fucking idiot?

Name: Anonymous 2012-02-25 15:06

not your personal homework army

Name: Anonymous 2012-02-25 15:07

>>4
I'm still not too sure what the acutal programming question is -(.

Name: Anonymous 2012-02-25 16:23

Dave grunted as he slowly pushed the terrified cucumber into his ass.

Name: Anonymous 2012-02-25 16:27

>>6 grunted as he slowly pushed the forced meme into my /prog/.

Name: Anonymous 2012-02-25 16:52

>>8 grunted as he slowly pushed the >>7 out of /prog/.

Name: Anonymous 2012-02-25 17:04

>>10 grunted as he slowly grunted the grunty grunt in his cunty cunt.

Name: Anonymous 2012-02-25 17:06

*hnnng*

Name: Anonymous 2012-02-25 17:07

>>6-10 grunted as they slowly checked >>11's lucky dubs.

Don't change these.
Name: Email:
Entire Thread Thread List