974 - Kaprekar Numbers

All about problems in Volume 9. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

974 - Kaprekar Numbers

Post by Jan » Tue Oct 31, 2006 6:18 pm

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.
Ami ekhono shopno dekhi...
HomePage

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Thu Nov 02, 2006 4:55 pm

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
Last edited by helloneo on Fri Nov 03, 2006 5:17 pm, edited 1 time in total.

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Thu Nov 02, 2006 5:32 pm

You should print "case" with a small 'c' :)

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Fri Nov 03, 2006 5:16 pm

little joey wrote:You should print "case" with a small 'c' :)
Thanks a lot.. :D

<:3)~~
New poster
Posts: 16
Joined: Wed Dec 06, 2006 6:57 pm

Post by <:3)~~ » Wed Dec 06, 2006 7:01 pm

is 99 also a Kaprekar no.
99*99=9801
98+01=99.
Is this correct :-?

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Wed Dec 06, 2006 7:50 pm

YES

<:3)~~
New poster
Posts: 16
Joined: Wed Dec 06, 2006 6:57 pm

Post by <:3)~~ » Wed Dec 06, 2006 8:16 pm

hey dude can u tell me if i am missing any no.??
*deleted*
THX THX
U GUYS R REALLY COOL
Last edited by <:3)~~ on Thu Dec 07, 2006 8:40 am, edited 1 time in total.

User avatar
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind » Wed Dec 06, 2006 8:45 pm

No :D

<:3)~~
New poster
Posts: 16
Joined: Wed Dec 06, 2006 6:57 pm

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

Post by <:3)~~ » Thu Dec 07, 2006 7:25 am

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*
Last edited by <:3)~~ on Thu Dec 07, 2006 8:41 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Dec 07, 2006 8:27 am

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.
Ami ekhono shopno dekhi...
HomePage

rezaeeEE
New poster
Posts: 25
Joined: Fri May 11, 2007 3:45 pm

why wa?

Post by rezaeeEE » Tue May 22, 2007 10:26 pm

code]
removed aftre accept

why wa?
help.
[/code]
Last edited by rezaeeEE on Wed May 23, 2007 4:05 pm, edited 1 time in total.

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish » Wed May 23, 2007 3:05 am

I think coloured number isn't correct. It should be 2223.

Code: Select all

//EDITED
>>>>ayeshapakhi
Thanks for ur suggestion
Hope it heps.
Last edited by mmonish on Thu May 24, 2007 12:13 pm, edited 3 times in total.

ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

Post by ayeshapakhi » Wed May 23, 2007 3:47 pm

hi there!!

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

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

Post by andysoft » Fri Aug 24, 2007 12:07 pm

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?
Now I lay me down to sleep...
my profile

mukeshtiwari
Learning poster
Posts: 63
Joined: Tue Mar 07, 2006 6:51 pm
Location: india

Post by mukeshtiwari » Thu Sep 06, 2007 12:40 am

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]);
				}
			}
	}
	

Post Reply

Return to “Volume 9 (900-999)”