Created
October 3, 2012 10:17
-
-
Save henteko/3826237 to your computer and use it in GitHub Desktop.
Project Euler #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int gcd(int a,int b) { | |
if(a == b) return a; | |
if(a < b) return gcd(a,b-a); | |
if(a > b) return gcd(a-b,b); | |
} | |
int main () { | |
int MAX = 12000; | |
float a = 1.0/3,b = 1.0/2; | |
int count = 0; | |
for(float i=2;i <= MAX;i++) { | |
for(float j=1;j < MAX;j++) { | |
if(i <= j) continue; | |
if(j/i <= a || j/i >= b || (j == 1 && i == 3)) continue; | |
if(gcd(i,j) == 1) count++; | |
} | |
} | |
cout << count << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment