Skip to content

Instantly share code, notes, and snippets.

@henteko
Created October 3, 2012 10:17
Show Gist options
  • Save henteko/3826237 to your computer and use it in GitHub Desktop.
Save henteko/3826237 to your computer and use it in GitHub Desktop.
Project Euler #73
#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