-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem33.cpp
More file actions
64 lines (60 loc) · 2.97 KB
/
Problem33.cpp
File metadata and controls
64 lines (60 loc) · 2.97 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
/*
Krishna Mohan
Project Euler - Problem 33
Date: 3/22/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define MAX 100
int gcd(int a, int b)
{
if(b==0)
return a;
return gcd(b, a%b);
}
int main() {
double div1, div2;
int a, b, c, d, num=1, den=1, g;
for(int i=11;i<MAX;i++)
{
for(int j=i+1;j<MAX;j++)
{
div1=(double)i/j;
a=i%10, b=(i/10)%10, c=j%10, d=(j/10)%10;
if(a==c || a==d || b==c || b==d)
{
div2=-1;
if(a==c && d!=0)
div2=(double)b/d;
else if(a==d && c!=0)
div2=(double)b/c;
else if(b==c && d!=0)
div2=(double)a/d;
else if(b==d && c!=0)
div2=(double)a/c;
/*(i==30 && j==50)
{
cout<<a<<" : "<<b<<" : "<<c<<" : "<<d<<endl;
cout<<div1<<" : "<<div2<<endl;
}*/
if(div1==div2)
{
if(a!=0 && b!=0 && c!=0 && d!=0)
{
//cout<<i<<"/"<<j;
g=gcd(j, i);
//cout<<" -> "<<(i/g)<<"/"<<(j/g)<<endl;
num*=i/g;
den*=j/g;
}
//cout<<a<<" : "<<b<<" : "<<c<<" : "<<d<<endl;
//cout<<div1<<" : "<<div2<<endl;
}
}
else
continue;
}
}
cout<<(den/gcd(den, num))<<endl;
return 0;
}