ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1104. Don’t Ask Woman about Her Age

Math hint and some more ...
Posted by Anton 18 Oct 2011 13:36
First of all. If you get WA#1, check how you scan input stream, cause they've put some trash in file.

I used the following idea. The whole number with base k divisible by ( k - 1 ), if sum( div( digit[ i ] ) ) is divisible by ( k - 1 ). Where digit[ i ] is k-based digit in input number ( char from input stream ); div( digit[ i ] ) is a remainder of division digit[ i ] * k by ( k - 1 ). Let see digit on i-th position, for example, it's A. So in decimal implementation it's equal to A * k ^ i.
A * k ^ i = A * k^i - A * k^(i-1) + A * k^(i-1) = A * k^(i-1) * ( k - 1 ) + A * k^(i-1)
A * k^(i-1) * ( k - 1 ) is divisible by ( k - 1 ), so we have to check only A * k^(i-1). If we repeat the same logic to this expression (i - 2) times, we see, that we have to check division A * k / ( k - 1 ).

I tried my best to explain the main idea, sorry if it can't be understood.
Re: Math hint and some more ...
Posted by Bogatyr 28 Nov 2012 20:18
You don't need your "div()".
Re: Math hint and some more ...
Posted by Kungfu_Panda 22 Apr 2015 19:49
Isn't it okay to just find the digital sum of the given number and add 1?
Re: Math hint and some more ...
Posted by zhangweilst 7 Jan 2016 17:25
Thank you. And we even can go a step further. Now see, A * k = A * k - A + A = A(k - 1) + A, So what we need to examine is just whether sum( digit[i]) is divisible by ( k - 1).