Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Problem With Max Limit of n.

$
0
0

PRPALIN For this question, i have pasted my solution below. I am getting correct output for all values of n <100000 after that i am not getting correct answer. Can someone help me out.

Solution Link

#include<stdio.h>
int f1(int n);
int palind(int n);
int main(){
 int n;
scanf("%d",&n);
printf("%d",f1(n));

return 0;
}
 int f1( int n)
{

while(n<1000000){
int k,flag=1,palin;
if ( ( (!(n & 1)) && n != 2 ) || (n < 2) || (n % 3 == 0 && n != 3) )
flag=0;

if(flag==1){
for(k=1;36*k*k-12*k<n;++k){
if((n%(6*k+1))==0||(n%(6*k-1)==0))
flag=0;
}
}
if(flag==1){
palin=palind(n);
if(palin==1)
return n;
}

n++;
}
}
int palind( int n)
{

 int sum=0,num=n;
while(n>0){

sum=sum*10+n%10;

n/=10;

}

if(sum==num)
return 1;
else
return 0;

}

Viewing all articles
Browse latest Browse all 40121

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>