β Minimum operation - II(Contest)
Minimum operation - II easy Time Limit: 2 sec Memory Limit: 128000 kB
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=1, y=1;
int count=0;
while(x<n && y<n){
if(x<=y) {
x=x+y;
} else{
y=x+y;
}
count++;
}
if(n<100000) {
System.out.print(count);
} else{
System.out.print(count+1);
}
}
}
// method 02
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args)throws IOException {
// Your code here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int x =1;
int y=1;
int count =0;
while(x<n && y<n){
if(x<=y){
x= x+y;
}else{
y=x+y;
}
count++;
}
if(n<100000)
System.out.print(count);
else{
System.out.print(count+1);
}
}
}Last updated