anupam's blog

By anupam, history, 4 years ago, In English

Initially I use GNU C++17 when I submit codes. I submitted code for 235A — LCM Challenge and got WA on test 61 using GNU C++17. Then again I submitted the same code in GNU C++14 and got Accepted. My submissions are here,

GNU C++17: 78659557 (Wrong answer on test 61)

GNU C++14: 78659665 (Accepted)

I found no explanation of it and thinking about what if it happened in contest time. Can you suggest me any reason? Thank you so much!

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +38 Vote: I do not like it

C++17 adds the functions std::lcm and std::gcd. In C++17 your code actually calls std::lcm(int,int) which returns an int, leading to overflow. In C++14 such a function doesn't exist so the program uses your function which doesn't overflow.