#include
#include
#include
using namespace std;
int main() {
int t, c1, c2, res;
string str1, str2;
cin
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.