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 | 3581 |

2 | OO0OOO00O0OOO0O0…O | 3327 |

3 | Petr | 3161 |

4 | LHiC | 3158 |

5 | CongLingDanPaiSh…5 | 3116 |

6 | ko_osaga | 3115 |

7 | mnbvmar | 3111 |

8 | Um_nik | 3104 |

9 | Benq | 3098 |

10 | Swistakk | 3089 |

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

1 | Radewoosh | 185 |

2 | Errichto | 163 |

3 | rng_58 | 161 |

4 | tourist | 158 |

5 | Vovuh | 150 |

5 | Um_nik | 150 |

7 | Petr | 149 |

7 | Swistakk | 149 |

9 | PikMike | 148 |

10 | 300iq | 147 |

10 | neal | 147 |

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: Oct/18/2018 07:13:03 (f1).

Desktop version, switch to mobile version.

Supported by

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