What's wrong with long? Why is subtracting 1 automatically?

后端 未结 1 1117
野趣味
野趣味 2021-01-28 17:57
#include 
#include 
#include 

using namespace std;

int main() {
    int t, c1, c2, res;
    string str1, str2;

    cin          


        
相关标签:
1条回答
  • 2021-01-28 18:16

    Some pow implementations return inaccurate results even when exact results are representable. Microsoft’s pow implementation is notorious for this.

    In (long)(((pow(10, c1) - 1) / 9) * ((pow(10, c2) - 1) / 9)), pow is returning a value slightly less than the correct value, such as returning 99999.999999999985448084771633148193359375 instead of 100000. This results in the rest of the arithmetic producing a value slightly less than 1221 instead of 1221. When that is converted to long, the fraction is truncated, producing 1220.

    Ideally, enough people would complain to Microsoft about this, or other publishers of bad pow routines, that they would fix it.

    Given that the problem exists, you can work around it by rounding the pow result to the nearest integer (as with the round function) or by writing your own power routine to suit your purposes.

    0 讨论(0)
提交回复
热议问题