forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP73.cpp
More file actions
66 lines (63 loc) · 1.34 KB
/
P73.cpp
File metadata and controls
66 lines (63 loc) · 1.34 KB
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
#include<iostream>
#include<fstream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iomanip>
#define MAXN 12000
#define MOD 1000000
#define LL long long
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
//递归写法
int SearcReuProFrac(int y1, int y2)
{
int b = y1 + y2;// the theory of Farey sequences
if(b <= MAXN)
return SearcReuProFrac(y1, b) + SearcReuProFrac(b, y2) + 1;
return 0;
}
//非递归写法
/*
int Stack[MAXN];
int SearcReuProFrac(int left, int right)
{
Stack[++Stack[0]] = right;
int mid, cnt = 0;
while(Stack[0])
{
mid = left + right;
if(mid <= MAXN)
{
Stack[++Stack[0]] = mid;//入栈
cnt++;//入栈的为满足题意
right = mid;
}
else
{
left = right;
right = Stack[--Stack[0]];//栈顶(值为right)出栈后,取栈顶元素
}
}
return cnt;
}
*/
int main()
{
clock_t start = clock();
printf("%d\n", SearcReuProFrac(3, 2));
printf("time cost: %lf", (double)( clock() - start) / CLOCKS_PER_SEC);
return 0;
}