Hi jures and welcome to bytes.com!
I just checked my local g++ installation and it doesn't seem to support the C++11 standard; C++98 seems to be the closest I can get. Compiling with that I had to change a few things as the
pow function isn't defined for an int and a long long value. Here's what I came up with:
- #include<cmath>
-
#include<iostream>
-
-
using namespace std;
-
-
int main() {
-
unsigned long long X, j, total = 0;
-
int i;
-
cin >> X;
-
-
for ( i = 0 ; i < 18 ; ++i ) {
-
total += 9*(i+1)*pow(10.,i);
-
//cout << "total : " << total << endl;
-
if ( total >= X ) break;
-
}
-
-
cout << total << endl;
-
}
-
You will notice two slight differences to your code:
i is an int rather than an unsigned long long and the first argument of that pow function is now a double value (due to the point after the digits). This not only compiles but for the input 40000 it indeed returns 488889 as you expect. If I take out the commented line, the output is as follows:
- total : 9
-
total : 189
-
total : 2889
-
total : 38889
-
total : 488889
-
488889
-
So, the question is: Does that code work for you and if not, where does it go wrong?