题目链接:https://projecteuler.net/problem=71

If n<d and HCF(n,d)=1, it is called a reduced proper fraction.

n/d 真分数升序排序后,离 3/7最近的数,d<=1000000

Java程序:

public class P71{
void run(){
calculate();
}
void calculate(){
int max_n = 1000000;
long a = 3;
long b = 7;
long r = 0;
long s = 1;
int q = 0;
long p = 0;
for( q = max_n;q>2;q--){
p = (a*q-1)/b;
if(p*s>r*q){
s = q;
r = p;
}
}
System.out.println(r+"/"+s);
} public static void main(String[] args){
long t0 = System.currentTimeMillis();
new P71().run();
long t1= System.currentTimeMillis();
System.out.println((t1-t0)+"ms");
}
}
04-13 09:53