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.

# | User | Rating |
---|---|---|

1 | tourist | 3496 |

2 | Um_nik | 3337 |

3 | Petr | 3298 |

4 | W4yneb0t | 3218 |

5 | Radewoosh | 3216 |

6 | OO0OOO00O0OOO0O0…O | 3188 |

7 | Syloviaely | 3168 |

8 | izrak | 3109 |

9 | anta | 3106 |

10 | fateice | 3099 |

# | User | Contrib. |
---|---|---|

1 | tourist | 184 |

2 | rng_58 | 170 |

3 | csacademy | 165 |

4 | Petr | 158 |

5 | Swistakk | 154 |

6 | lewin | 149 |

7 | Errichto | 147 |

8 | matthew99 | 145 |

9 | Zlobober | 141 |

9 | adamant | 141 |

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.

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/20/2018 11:00:57 (d2).

Desktop version, switch to mobile version.

User lists

Name |
---|

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

Can you explain me the difference between your code and my code I am beginner so please bear with me

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.

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

Thanks so much