-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1049. Brave Balloonists.c
77 lines (62 loc) · 1.3 KB
/
1049. Brave Balloonists.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <math.h>
#define NMAX 10000
#define NR 10
int primes[1300] = {0};
int isPrime(int n)
{
int i;
if (n == 1 || n == 2)
return 1;
if (n % 2 == 0)
return 0;
int k = sqrt(n) + 1;
for (i = 3; i <= k; i = i + 2)
if (n % i == 0)
return 0;
return 1;
}
void compute_primes(char factors[], int N)
{
int i = 1;
while (N != 1)
{
if (N % primes[i] == 0) {
factors[i] += 1;
N = N / primes[i];
}
else
i++;
}
factors[++i] = 0;
}
int main(void)
{
int i, j;
int nr_primes = 0;
/* Generate prime numbers */
for (i = 1; i < 10000; i++)
if (isPrime(i))
primes[nr_primes++] = i;
char factors[NR][10001] = {0};
for (i = 0; i < NR; i++)
for (j = 0; j < 10001; j++)
factors[i][j] = 0;
for (i= 0; i < NR; i++) {
int N;
scanf("%d", &N);
compute_primes(factors[i], N);
}
int total = 1;
for (j = 1; j <= 10000; j++)
{
int sum = 0;
for (i = 0; i < NR; i++)
sum += factors[i][j];
if (sum > 0) {
total = total*(sum + 1);;
}
}
printf("%d \n", total % 10);
return 0;
}