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 1095. Nikifor 3

Any hint, please?
Posted by Li Yi 6 Oct 2001 13:46
Re: Any hint, please?
Posted by Huang Yizheng 1 Nov 2001 17:48
>I think only search is okey.
Re: Any hint, please?
Posted by Coldfeel 30 Mar 2003 15:07
>I think only search is okey.

ur solution is not good.

the better way is use remainder(mod)
Re: Any hint, please?
Posted by Kit 12 Apr 2005 00:12
I wanna offer my solution (I think, author had in view same method).
Arrange digits of the number in a such way:
(non-zero digits in arbitrary order)1234(all zeroes).
Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it).

Edited by author 12.04.2005 01:20
Re: Any hint, please?
Posted by Nickolas 26 Feb 2008 18:59
Is anybody willing to tell me why it works?
Re: Any hint, please?
Posted by unlucky [Vologda SPU] 23 Feb 2010 14:04
Kit wrote 12 April 2005 00:12
I wanna offer my solution (I think, author had in view same method).
Arrange digits of the number in a such way:
(non-zero digits in arbitrary order)1234(all zeroes).
Then, we can permute only 1234 among them in order to receive a number, dividing by 7 (You can prove it).

Edited by author 12.04.2005 01:20
No sorting, just "cutting" one : 1,2,3,4 from input number; selecting zeros and constructing "possible answer" :)
Re: Any hint, please?
Posted by Madhav 23 Sep 2010 02:45
cant we use dynamic programming.It is a O(2^numberofdigits) algorithm. Can any one tell me why the other solution works?
Re: Any hint, please?
Posted by Artem Khizha [DNU] 21 Aug 2011 16:05
@Nickolas

> Is anybody willing to tell me why it works?

You can write a sample program and see, that permutations of 1234 produce all possible remainders in division by 7. So <some non-zero numbers><permutation on 1234><zeros> always fits.
Re: Any hint, please?
Posted by Takanashi Rikka 2 Mar 2016 11:48
Just use random_shuffle.