-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProjectEuler#1.c
55 lines (47 loc) · 1.38 KB
/
ProjectEuler#1.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
long long int t,k,n,sum=0,sum2=0,i,p,m;
scanf("%lld",&t);
for(k=0;k<t;k++)
{
scanf("%lld",&n);
m=p=n;
if((n%3)!=0)
{
n=n/3;
sum=((n)*(6+(n-1)*3))/2;
}
else if((n%3)==0)
{
n=n/3-1;
sum=((n)*(6+(n-1)*3))/2;
}
if((m%5)!=0)
{
m=m/5;
sum=sum+((m)*(10+(m-1)*5))/2;
}
else if((m%5)==0)
{
m=m/5-1;
sum=sum+((m)*(10+(m-1)*5))/2;
}
if((p%15)!=0)
{
p=p/15;
sum2=((p)*(30+(p-1)*15))/2;
}
else if((p%15)==0)
{
p=p/15-1;
sum2=((p)*(30+(p-1)*15))/2;
}
sum=sum-sum2;
printf("%lld\n",sum);
sum=sum2=0;
}
return 0;
}