ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1104. Не спрашивай даму о возрасте

Math hint and some more ...
Послано Anton 18 окт 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 ...
Послано Bogatyr 28 ноя 2012 20:18
You don't need your "div()".
Re: Math hint and some more ...
Послано Kungfu_Panda 22 апр 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 ...
Послано zhangweilst 7 янв 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).