When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

FReAk's blog

By FReAk, history, 3 years ago, In English

Can anybody explain why there is a variation in answer if I change the c++ version ?

problem link : 1228C - Primes and Multiplication

My submission got wrong verdict in testcase 14 using GNU C++17 (64) 116231648

My submission got AC using GNU C++17 116231294

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

| Write comment?
»
3 years ago, # |
Rev. 3   Vote: I like it +15 Vote: I do not like it

The issue is with the pow function, the value returned by it can overflow double.

  1. Either typecast the values to long double before passing (AC code), or
  2. Just use powl()

See this for more details.

I am not sure, why it worked for the 32-bit version

32 bit g++ by default does all of its floating-point arithmetic with (80 bit) long double. See this for more info.