Page 1 of 2
11332 - Summing Digits
Posted: Wed Nov 14, 2007 8:07 am
by apurba
is there any algorithm for the problem? very east to understand but its really troubling.
Posted: Wed Nov 14, 2007 8:21 am
by rio
Straight ford algorithm. Just calculate.
PS. Please change the title to "11332 - Summing Digits"
----
Rio
Re: 11332_summing digits--- is troubling very simply!!!!
Posted: Wed Nov 14, 2007 8:25 am
by sclo
apurba wrote:is there any algorithm for the problem? very east to understand but its really troubling.
It is the most trivial problem from that problem set.
Posted: Wed Nov 14, 2007 9:22 am
by shakil
It's really easy.You can take input in string.And make it digit sum in long.
And next again find digit sum until it one digit.
Posted: Wed Nov 14, 2007 9:27 am
by apurba

that is what i am thinking about.............using string.
Posted: Wed Nov 14, 2007 9:57 am
by apurba
it is not so simple for all.

Posted: Wed Nov 14, 2007 5:11 pm
by S.M.ferdous
If a number is divisible by 9 the sum of its digits succesively reduced to 9
or the sum of digits will be reduced to num mod 9.
As for xample 198 = 1+9+8 = 18 = 1+8 = 9 (as 198 mod 9 == 0)
agan 203 = 2+0+3 = 5 (203 mod 9 =5)
so in this problem one doesn't need to calculate any summation but simply mod operation by 9.
S.M.Ferdous
Posted: Tue Nov 20, 2007 4:24 pm
by RC's
You're right..
There is no need to calculate it using a string.
Besides, your algorithm is very fast.
Thanks..
Posted: Mon Feb 25, 2008 6:18 pm
by turcse143
using recursion algorithm it may be solved.
n=123456
f(n)=1+2+3+4+5+6=21
f1(n)=2+1=3
if(n<9)
return;
Re: 11332 - Summing Digits
Posted: Sun May 25, 2008 11:34 am
by Obaida
My bad luck why every time it's me getting WA...
Can someone check this.
Re:
Posted: Sun May 25, 2008 3:19 pm
by helloneo
Obaida wrote:My bad luck why every time it's me getting WA...
Can someone check this.
Try this input
My output is
Re: 11332 - Summing Digits
Posted: Mon May 26, 2008 5:51 am
by Obaida
Thank you helloneo that was a misunderstanding. I got Accepted.
Re: 11332 - Summing Digits
Posted: Fri Jun 20, 2008 8:50 am
by lnr
Code: Select all
This is a very is ploblem in this volume.
Re: 11332 - Summing Digits
Posted: Fri Aug 08, 2008 11:17 am
by mrmbdctg
I am getting wrong answer with this code. Please help me
Re: 11332 - Summing Digits
Posted: Sat Aug 09, 2008 8:29 am
by Bluefin
my algorithm is
Code: Select all
1. int sum = add every digit of n, since n is at most 2,000,000,000, sum has two digits at most.
2. int temp = sum/10 + sum %10
3. if temp < 10, print temp
else print temp / 10 + temp % 10
this algorithm isn't very fast, but it works
