## 11332 - Summing Digits

Moderator: Board moderators

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

### 11332 - Summing Digits

is there any algorithm for the problem? very east to understand but its really troubling.
Last edited by apurba on Wed Nov 14, 2007 8:23 am, edited 1 time in total.

Code: Select all

``keep dreaming...``

rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan
Straight ford algorithm. Just calculate.

PS. Please change the title to "11332 - Summing Digits"
----
Rio

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Contact:

### Re: 11332_summing digits--- is troubling very simply!!!!

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.

shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Contact:
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.
SHAKIL

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

that is what i am thinking about.............using string.

Code: Select all

``keep dreaming...``

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm
it is not so simple for all.

Code: Select all

``keep dreaming...``

S.M.ferdous
New poster
Posts: 13
Joined: Fri Nov 03, 2006 2:53 pm
Contact:
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

RC's
Learning poster
Posts: 65
Joined: Fri Jul 13, 2007 3:17 pm
You're right..
There is no need to calculate it using a string.
Besides, your algorithm is very fast.
Thanks..

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
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;
''I want to be most laziest person in the world''

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Re: 11332 - Summing Digits

My bad luck why every time it's me getting WA...
Can someone check this.

Code: Select all

``Got Accepted``
Last edited by Obaida on Mon May 26, 2008 5:49 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

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

### Re:

Obaida wrote:My bad luck why every time it's me getting WA...
Can someone check this.

Try this input

Code: Select all

``````9
18
27
0``````
My output is

Code: Select all

``````9
9
9``````

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Re: 11332 - Summing Digits

Thank you helloneo that was a misunderstanding. I got Accepted.
try_try_try_try_&&&_try@try.com
This may be the address of success.

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm

### Re: 11332 - Summing Digits

Code: Select all

``````This is a very is ploblem in this volume.
``````

mrmbdctg
New poster
Posts: 18
Joined: Sun Mar 04, 2007 7:12 am
Contact:

### Re: 11332 - Summing Digits

Code: Select all

``````Accepted
``````
Last edited by mrmbdctg on Thu Aug 14, 2008 9:27 pm, edited 1 time in total.
Mizanur Rahaman Mizan
USTC, CHITTAGONG
Website:http://www.teronga.com

Bluefin
New poster
Posts: 20
Joined: Sat Jul 08, 2006 3:39 pm
Contact:

### Re: 11332 - Summing Digits

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
"It's nice to be important, but it's more important to be nice"

http://bluefintuna.wordpress.com/