LoginSignup
1
0

More than 5 years have passed since last update.

topcoder 問題をちょっと解いてみようかな。SRM 622 DIV2 FibonacciDiv2

public class FibonacciDiv2 {

public int find(int N) {
    if (N == 1) {
        return 0;
    }
    int a1 = 1, a2 = 1, a3= 1;
    int min = Integer.MAX_VALUE;
    while (true) {
        a3 = a1 + a2;
        a1 = a2;
        a2 = a3;
        min = Math.min(min, Math.abs(a3 - N));
        if (a3 > N) {
            break;
        }
    }
    return min;
}

}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0