974 - Kaprekar Numbers
Moderator: Board moderators
974 - Kaprekar Numbers
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.
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
HomePage
Hello..~
I got PE for this problem..
How can I avoid PE..?
I print blank line between each case except for the last one..
Thanks.. ![:D](./images/smilies/icon_biggrin.gif)
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
![:D](./images/smilies/icon_biggrin.gif)
Last edited by helloneo on Fri Nov 03, 2006 5:17 pm, edited 1 time in total.
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
can u plz tell me whats wrong then with this code????
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*
*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.
Your code is not right.
Replace the following part
with
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.
Replace the following part
Code: Select all
while(arr[i]>=a && arr[i]<=b)
{printf("\n%d",arr[i]);i++;p=87;}
Code: Select all
if(arr[i]>=a && arr[i]<=b)
{printf("\n%d",arr[i]);p=87;}
Remove your code and all the numbers you have posted.
Ami ekhono shopno dekhi...
HomePage
HomePage
I think coloured number isn't correct. It should be 2223.
Hope it heps.
Code: Select all
//EDITED
>>>>ayeshapakhi
Thanks for ur suggestion
Last edited by mmonish on Thu May 24, 2007 12:13 pm, edited 3 times in total.
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
-
- Experienced poster
- Posts: 109
- Joined: Sat Jun 23, 2007 9:53 pm
- Location: Brest, BELARUS
- Contact:
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?
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
my profile
-
- Learning poster
- Posts: 63
- Joined: Tue Mar 07, 2006 6:51 pm
- Location: india
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]);
}
}
}