7.1-WY22 Fibonacci数列
Fibonacci数列_牛客题霸_牛客网 (nowcoder.com)
- import java.util.*;
- public class Main {
- public static void main(String[] args){
- Scanner sc=new Scanner(System.in);
- while(sc.hasNext()){
- int n=sc.nextInt();
- int first=0;
- int second=1;
- int third=1;
- while(n>second){
- third=first+second;
- first=second;
- second=third;
- }
- int ret=Math.min(n-first,second-n);
- System.out.println(ret);
- }
- }
- }