BUPT-homework/pset4/5-squares.c

26 lines
344 B
C
Raw Normal View History

2021-10-19 23:51:15 +08:00
#include <stdio.h>
// Function prototypes
int dividable(int n);
int main(void)
{
// Initialize variables and get input
int n, sum = 0;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
if (dividable(i)) {
sum += i;
}
}
printf("%d\n", sum * sum);
return 0;
}
int dividable(int n) {
return (n % 3 == 0 && n % 7 == 0) ? 1 : 0;
}