motatoes's blog

By motatoes, history, 5 years ago, In English

Hi Codeforces

I have been trying to solve this problem on SPOJ: https://www.spoj.com/problems/EASYMATH/

My bruteforce solution is ofcourse TLE'd and I came across this solution: https://github.com/Emsawy/Competitive-Programming/blob/master/SPOJ/EASYMATH.cpp

I have difficulty understanding the "go" function. There is a recursive call and it is calculating the LCM of all the divisors? Can someone explain the logic behind this function in simple terms? Is there a formula for this?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Learn inclusion exclusion principle to solve this. It's not hard, and you don't event need the code you are looking into :)