-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5주차퀴즈3.cpp
101 lines (88 loc) · 1.3 KB
/
5주차퀴즈3.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
#include <stdio.h>
int fivo[100];
int top = -1;
long long fibo(int n) // 동적프로그래밍 방식
{
if (n <= 2) {
return 1;
}
else if (n > top) //쓰레기값일때
{
fivo[n] = fibo(n - 1) + fibo(n - 2);
top = n;
}
return fivo[n];
}
int main() {
long long f = 0;
int count;
int sum = 0;
for (int i = 2; i < 1000000; i++) {
f = fibo(i);
}
for (int i = 0; i <= top; i++) {
count = 0;
for (int j = 2; j < fivo[i]; j++) {
if (fivo[j] % j != 0) {
count++;
}
if (count == 0) {
printf("%d", i);
sum += i;
}
}
}
printf(" += %d", sum);
printf("\n");
}*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int fivo[100];
int top = -1;
long long fibo(int n)//동적프로그래밍?
{
if (n <= 2) {
return 1;
}
else if (n > top) {
fivo[n] = fibo(n - 1) + fibo(n - 2);
top = n;
}
return fivo[n];
}
int is_prime(int n)
{
if (n < 2) {
return 0;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int main(){
int k;
int len;
scanf("%d", &k);
for (int i = 1; i < 100; i++) {
if (fibo(i) >= k) {
len = k - 1;
}
else {
continue;
}
}
long long sum = 0;
for (int i = 1; i <= len; i++) {
long long f = fibo(i);
if (is_prime(f)) {
printf("%lld ", f);
sum += f;
}
}
printf("+= %lld\n", sum);
return 0;
}