Code:
x *= y /*same as*/ x = x * y
Nope
Code:
x *= y /*is the same as*/ x = x * (y)
So
Code:
x *= y + 1 /*is the same as*/ x = x * (y + 1)
The number of factors can be calculated by finding only the prime factors then multiplying the exponents of the prime factors (i.e., how many times they occur) plus one together. E.g., if the number is 360 = 2*2*2*3*3*5 then the number of factors is 4 * 3 * 2 = 24.
Code:
#include <stdio.h>
int main() {
// Loop through triangular numbers
for (int i = 1, n = 1; ; n += ++i) {
int m = n, nfacts = 1, cnt = 0;
// Calculate number of factors
for (int d = 2; m > 1; ) {
if (m % d == 0) {
++cnt;
m /= d;
}
else {
nfacts *= cnt + 1;
cnt = 0;
++d;
}
}
nfacts *= cnt + 1;
if (nfacts >= 500) {
printf("%5d %8d %5d\n", i, n, nfacts);
break;
}
}
return 0;
}
Result: the 12375th triangular number, 76576500, has 576 factors.