Here is my code for the problem : http://ideone.com/UHbff
I got WA because on Codeforces judge for input 1 10000, its giving 10007 but on ideone and my system it gives 10008. Am i using any compiler version dependent statement ?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
Here is my code for the problem : http://ideone.com/UHbff
I got WA because on Codeforces judge for input 1 10000, its giving 10007 but on ideone and my system it gives 10008. Am i using any compiler version dependent statement ?
Name |
---|
http://www.cplusplus.com/reference/clibrary/cmath/pow/
http://stackoverflow.com/questions/8174909/pow-calculates-wrong
http://www.codeforces.ru/contest/205/submission/1896769
It's because of using the
pow
function. It returns double/float and in some versions (for example, MinGW) it can result in something like 999999.999999 instead of 1000000 which is rounded to 999999.Never use such floating point functions when you need to work with integers. You never know what it'll return. You'd better to write your own function
powll
which works withlong long
sAhh, i knew beforehand that pow might cause problem and i tested on MinGW-g++(windows) + g++(Linux) on several test cases before submission( indeed i shouldn't have relied on those test cases output ). I think apart from compiler its somewhat system dependent also.