### ymrg3307's blog

By ymrg3307, history, 12 months ago, ,

http://codeforces.com/contest/460/submission/34483323

Above is the Link for my solution to the 'Vasya and socks' problem please clarify me where i am going wrong in my algorithm.

•
• +3
•

 » 12 months ago, # |   +3
•  » » 12 months ago, # ^ |   0 Can you explain me the difference between your code and my code I am beginner so please bear with me
•  » » » 12 months ago, # ^ |   +1 Consider a simple example n=7 m=2 . Lets first calculate correct answer so first n=7. It means the days {1,2,3,4,5,6,7} Here we can buy a pair of socks on second days so we will buy on 2,4,6 . Meaning 3 new pair of socks now the set is {1,2,3,4,5,6,7,8,9,10}. Now we can buy a pair of socks on 8 and 10 . meaning 2 new pair of socks now the set will be {1,2,3,4,5,6,7,8,9,10,11,12} . Now you can buy a pair of socks 12th day. So the set finally becomes {1,2,3,4,5,6,7,8,9,10,11,12,13}. so the answer is 13 where as your answer is 11.
•  » » » 12 months ago, # ^ | ← Rev. 4 →   +1 Now lets see what you do in your code . n=7 m=2 result=n days=n 1 iteration result=result/m // result becomes 7/2=3 days=days+result // result becomes 10 result is still greater than 0 2 iteration result=result/m // result becomes 3/2=1 days=days+result // result becomes 11 result is still greater than 0 3 iteration result=result/m // result becomes 1/2=0 days=days+result // result becomes 11 result is 0 so your answer becomes 11 Lets see what you are adding 7/2 + 3/2 + 1/2 = 3+1+0=4 what should have been done was 7/2 + 3/2 + 1/2=(7+3+1)/2=(11)/2=5 so the answer becomes days=7+5=12 and you can buy one more on 12th day. so answer is 13. What I mean is you have to consider modulo operation as well. http://codeforces.com/contest/460/submission/34511057
•  » » » » 12 months ago, # ^ |   0 Thanks so much