forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP33.cpp
More file actions
71 lines (71 loc) · 1.6 KB
/
P33.cpp
File metadata and controls
71 lines (71 loc) · 1.6 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
67
68
69
70
71
#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>
#define MAXN 1000000000
#define LL long long
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
int gcd(int x, int y)//x>y&&y!=0
{
int temp;
while(x%y)
{
temp = y;
y = x % y;
x = temp;
}
return y;
}
bool isLager(int a2, int a1, int b2, int b1)
{
if(b2>a2)
return true;
if(b2==a2&&b1>a1)
return true;
return false;
}
int main()
{
double duration;
clock_t start;
start = clock();
int numerator = 1, denominator = 1;
for(int i=1; i<=9; i++)
for(int j=i+1; j<=9; j++)//i<j
for(int k=1; k<=9; k++)
{
if(isLager(i,k,k,j)==true)
{
if((i*10+k)*j==(k*10+j)*i)
{
numerator*=i;
denominator*=j;
}
}
if(isLager(k,i,j,k)==true)
{
if((k*10+i)*j==(j*10+k)*i)
{
numerator*=i;
denominator*=j;
}
}
}
duration = ((double)(clock()-start))/CLOCKS_PER_SEC;
printf("%d\n",denominator/gcd(denominator, numerator));
printf("Time cost: %f s.\n", duration);
}