@dwhitney67: I already posted the link to the problem.
http://www.codechef.com/problems/K2. And yes I'll surely add what to input in print.
@marlonsm : Thanks dude. But for some strange reason its not giving output for large nos like(9876543219) after making the change. I have added a comment in the line I made the change
Have a look :
http://dl.dropbox.com/u/19182824/current_change.c
@gardnan : Its in C.
#include<stdio.h>
void convert(long long int number,long long int base,int *converted,int *index);
void palcheck( int converted[1000], int *index, int *test);
main()
{
long long int number,base;
int converted[1000],test=1,index,t,i;
printf("Enter the number of test cases : ");
scanf("%d",&t);
for(i=1;i<=t;i++)
{
test=1;
printf("Enter the number : ");
scanf("%lld",&number);
for(base=2;base<=number-1;base++)
{
convert(number,base,converted,&index);
palcheck(converted,&index,&test);
if(test==0) printf("The smallest base in which given number is palindromic is %lld \n",base) && (base=number+1);
}
if(test!=0) printf("The smallest base in which given number is palindromic is %lld \n",number+1);
}
}
void convert(long long int number,long long int base, int *converted,int *index)
{
int i;
for(i=1;number>0;i++)
{
converted[i]=number%base;
number=number/base;
}
*index=i-1;
}
void palcheck(int *converted , int *index, int *test)
{
int i,k=0,p;
for(i=1;i<=*index;i++)
{
if(converted[i]==converted[*index-i+1]) k++ ;
else (i=*index+1);
}
if(k==*index) *test=0;
else *test=1;
}
Or here is the file:
http://dl.dropbox.com/u/19182824/current_4.c
Thanks to everyone for your prompt replies!
Bookmarks