11332 - Summing Digits

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

Moderator: Board moderators

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

11332 - Summing Digits

Post by apurba »

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

Post by rio »

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
Location: Vancouver, BC, Canada
Contact:

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

Post 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.

shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

Post 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.
SHAKIL

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

Post by apurba »

:P
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

Post by apurba »

it is not so simple for all.
:o

Code: Select all

keep dreaming...

S.M.ferdous
New poster
Posts: 13
Joined: Fri Nov 03, 2006 2:53 pm
Location: bangladesh
Contact:

Post 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

RC's
Learning poster
Posts: 65
Joined: Fri Jul 13, 2007 3:17 pm

Post by RC's »

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
Location: (CSE,DU) Dhaka,Bangladesh

Post 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;
''I want to be most laziest person in the world''

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 11332 - Summing Digits

Post by Obaida »

My bad luck why every time it's me getting WA... :evil:
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:

Post by helloneo »

Obaida wrote:My bad luck why every time it's me getting WA... :evil:
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
Location: (BUBT) Dhaka,Bagladesh.

Re: 11332 - Summing Digits

Post by Obaida »

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
Location: Dhaka,Bangladesh

Re: 11332 - Summing Digits

Post by lnr »

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
Location: Bangladesh
Contact:

Re: 11332 - Summing Digits

Post by mrmbdctg »

I am getting wrong answer with this code. Please help me

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
BANGLADESH
Website:http://www.teronga.com

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

Re: 11332 - Summing Digits

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

http://bluefintuna.wordpress.com/

Post Reply

Return to “Volume 113 (11300-11399)”