-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem1.c
33 lines (29 loc) · 856 Bytes
/
problem1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/****************************************************
* Programmer: Maramkhah, Shayon
*
* Description: Find the sum of multiples 3 or 5 under 1000
*
*
*
*/
#include <stdio.h>
int main(void){
unsigned int limit = 1000;
const unsigned int M = 3;
const unsigned int commonDifference= M;
unsigned int n = (limit-1)/M;
unsigned int an = commonDifference+(n-1)*commonDifference;
unsigned int Sn= n*(M+an)/2;
unsigned int nn= (limit -1)/5;
const unsigned int W = 5;
unsigned int commondiff= W;
unsigned int ann = commondiff+(nn-1)*commondiff;
unsigned int Sm= nn*(W+ann)/2;
const unsigned int Z =15;
unsigned int nnn= (limit-1)/Z;
unsigned int comdif=Z;
unsigned int annn= comdif+(nnn-1)*comdif;
unsigned int Sz= nnn*(Z+annn)/2;
unsigned int sum = Sn+Sm-Sz;
printf("%u",sum);
}