Title description
Xiaoming of 2,0,1,9 digit numbers contained very interested in 1 to 40 the number of such packets
include 1,2,9,10 to 32, 39 and 40, a total of 28, and they are 574, the sum of squares is 14362.
Note that the sum of squares means that each number is squared separately and then summed.
May I ask, from 1 to 2019, what is the sum of the squares of all such numbers?
code show as below:
#include <iostream>
using namespace std;
bool check(int x) {
int c;
while (x) {
c = x % 10;
if (c == 0 || c == 2 || c == 1 || c == 9) {
return true;
}
x /= 10;
}
return false;
}
int main() {
long long res = 0;
for (int i = 1; i <= 2019; i++) {
if (check(i)) {
res += i * i;
}
}
cout << res << endl;
return 0;
}