Page 1 of 3

974 - Kaprekar Numbers

Posted: Tue Oct 31, 2006 6:18 pm
by Jan
I have written a solution and generated some cases. If anyone send me an alternate solution then I can verify the cases. Thanks.

You can send me a pm or mail at jan876_du@yahoo.com.

EDIT : I have got an solution from Joachim Wulff (little joey). Thanks Joachim.

Posted: Thu Nov 02, 2006 4:55 pm
by helloneo
Hello..~
I got PE for this problem..
How can I avoid PE..?
I print blank line between each case except for the last one..

Code: Select all

code removed
Thanks.. :D

Posted: Thu Nov 02, 2006 5:32 pm
by little joey
You should print "case" with a small 'c' :)

Posted: Fri Nov 03, 2006 5:16 pm
by helloneo
little joey wrote:You should print "case" with a small 'c' :)
Thanks a lot.. :D

Posted: Wed Dec 06, 2006 7:01 pm
by <:3)~~
is 99 also a Kaprekar no.
99*99=9801
98+01=99.
Is this correct :-?

Posted: Wed Dec 06, 2006 7:50 pm
by emotional blind
YES

Posted: Wed Dec 06, 2006 8:16 pm
by <:3)~~
hey dude can u tell me if i am missing any no.??
*deleted*
THX THX
U GUYS R REALLY COOL

Posted: Wed Dec 06, 2006 8:45 pm
by emotional blind
No :D

can u plz tell me whats wrong then with this code????

Posted: Thu Dec 07, 2006 7:25 am
by <:3)~~
can u plz tell me whats wrong then with this code????
*deleted*
O My God how can b i so stupid
THX A LOT BUDDY!!!*hugs*

Posted: Thu Dec 07, 2006 8:27 am
by Jan
Your code is not right.
Replace the following part

Code: Select all

while(arr[i]>=a && arr[i]<=b) 
{printf("\n%d",arr[i]);i++;p=87;}
with

Code: Select all

if(arr[i]>=a && arr[i]<=b) 
{printf("\n%d",arr[i]);p=87;}
Because when i=18, and the condition is ok, your code will try to access arr[19] which is not valid.
Remove your code and all the numbers you have posted.

why wa?

Posted: Tue May 22, 2007 10:26 pm
by rezaeeEE
code]
removed aftre accept

why wa?
help.
[/code]

Posted: Wed May 23, 2007 3:05 am
by mmonish
I think coloured number isn't correct. It should be 2223.

Code: Select all

//EDITED
>>>>ayeshapakhi
Thanks for ur suggestion
Hope it heps.

Posted: Wed May 23, 2007 3:47 pm
by ayeshapakhi
hi there!!

I think u should remove the Kaprekar numbers from ur posts...
otherwise spoilers will take the chance :oops: ..................
.............................

Posted: Fri Aug 24, 2007 12:07 pm
by andysoft
Hi!
I have sure got AC for this prob, but I am interested if there is any way to solve it not just by sending table of numbers?

Posted: Thu Sep 06, 2007 12:40 am
by mukeshtiwari
hello everybody . one thing that i can not understand the upper limit number . is upper limit number is 40000 digit long or something else . i am getting WA . here is my code . help me plz

Code: Select all

 #include<cstdio>


	
	int fun(int k)
		{
			long long int a[10],j,i=0,w1,w2,v,k1;
			k1=k*k;
			while(k1>0)
			 {
				a[i++]=k1%10;
				k1=k1/10;
			 }
			for(j=i-1;j>=0;j--)
			 {
				w1=w2=0;
				for(v=i-1;v>=j;v--)
				  w1=10*w1+a[v];
				for(;v>=0;v--)
				  w2=10*w2+a[v];
				//printf("%d %d\n",w1,w2);
				if(w1>0 && w2>0)
				   {
					if(w1+w2==k)
						return 1;
				   }
			}
				return 0;
		}	

	int main()
	  {

			int count=0,i,k,krep[1000000],j,n,l,h;
			for(i=2;i<=1000000;i++)
			  {
				
				if(fun(i))
					krep[i-2]=i;
				else
					krep[i-2]=0;
			  }
			scanf("%d",&n);
			for(i=0;i<n;i++)
			 {
				scanf("%d%d",&l,&h);
				if(i!=0)
					printf("\n");
				printf("case #%d\n",i+1);
				for(j=l;j<=h;j++)
				 {
					if(krep[j-2]!=0)
						printf("%d\n",krep[j-2]);
				}
			}
	}