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

2 | OO0OOO00O0OOO0O0…O | 3280 |

3 | Syloviaely | 3274 |

4 | Um_nik | 3248 |

5 | Petr | 3233 |

6 | fateice | 3230 |

7 | mnbvmar | 3096 |

8 | anta | 3053 |

9 | FizzyDavid | 3050 |

10 | LHiC | 3047 |

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

1 | Radewoosh | 166 |

2 | rng_58 | 161 |

3 | tourist | 160 |

4 | Petr | 152 |

5 | csacademy | 151 |

5 | Swistakk | 151 |

7 | Vovuh | 145 |

7 | Um_nik | 145 |

9 | Nickolas | 142 |

9 | Errichto | 142 |

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: Aug/18/2018 12:16:08 (d1).

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