← Back to topics
Topic

Task Gaus

V
Vidakovic
Whats wrong with my code?
How i can make him faster?

#include <iostream>
#include <cmath>
using namespace std;

int i,j(0),n,m;

int suma(int a) {
int ret(0);
while (a) {
ret += a % 10;
a /= 10;
}
return ret;
}

int main() {
int a,b,i,k;
cin>>a>>b;
k=0;
for (i=a;i<=b;i++)
if (suma(i) % 2 == 0) k+=1;
cout<<k<<endl;
system ("pause");
}
D
Dgleich
Well brute-force won't work in this task try finding some law about how many Positive Sums are from 1 to N and how many from 1 to M-1