You are given two natural numbers A and B. Count how many numbers in the interval [A; B] the sum of divisors will be odd. Restriction (1 <= A <= B <= 1000). I can't do the right amount, I will be glad to any help.
#include<iostream> using namespace std; int main() { int a = 1, b = 6, sum = 0, total = 0; for (int i = a; i <= b; ++i) { for (int j = 1; j< i ; ++j) { if (i % j == 0) sum += j;//Тут проблема if (sum % 2 != 0) ++total; sum = 0; } } cout << "Total:" << total << endl; system("pause"); return 0; }
sum = 0;- inside the loop, you check not the amount for oddness, but all subtotals. - KoVadim