Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; import java.math.*; public class c370C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x = in.nextInt(); int y = in.nextInt(); int[] sides = new int[]{y,y,y}; int minIndex = 0; int count = 0; while(sides[minIndex] < x) { count++; sides[minIndex] = sides[0]+sides[1]+sides[2]-sides[minIndex]-1; minIndex = sides[0]<sides[1] ? (sides[0]<sides[2] ? 0 : 2) : (sides[1]<sides[2]? 1 : 2); } System.out.println(count); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, incr; long long int x, y; cin >> x >> y; int result = 0; a = b = c = y; while (true) { if (a == x && b == x && c == x) break; result++; incr = a + b + c - min(a, min(b, c)) - 1; if (a <= b && a <= c) a = incr > x ? x : incr; else if (b <= a && b <= c) b = incr > x ? x : incr; else if (c <= a && c <= b) c = incr > x ? x : incr; } cout << result << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
// -*- coding: utf-8 -*- //import java.awt.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream; if (args.length > 0 && args[0].equals("devTesting")) { try { inputStream = new FileInputStream(args[1]); } catch(FileNotFoundException e) { throw new RuntimeException(e); } } else { inputStream = System.in; } OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { long x, y; void solve(int testNumber, InputReader in, PrintWriter out) { x = in.nextInt(); y = in.nextInt(); long cnt = 0; long[] sides = new long[3]; Arrays.fill(sides, y); while (sides[0] < x) { ++cnt; sides[0] = sides[1] + sides[2] - 1; Arrays.sort(sides); } out.println(cnt); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public boolean hasInput() { try { if (tokenizer != null && tokenizer.hasMoreTokens()) { return true; } reader.mark(1); int ch = reader.read(); if (ch != -1) { reader.reset(); return true; } return false; } catch(IOException e) { throw new RuntimeException(e); } } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class tp { public static void main(String args[]){ Scanner s= new Scanner(System.in); int x=s.nextInt(); int y= s.nextInt(); int a=y,b=y,c=y; int sec=1; while(true){ if(a>=x && b>=x && c>=x) { System.out.println(sec-1); return; } if(sec%3==1) a=b+c-1; else if(sec%3==2) b=a+c-1; else if(sec%3==0) c=a+b-1; sec++; } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x, a = map(int, input().split()) b = c = a res = 0 while a < x: a, b, c = b, c, b + c - 1 res += 1 print(res)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y = map(int,input().split()) cnt = 0 a=b=c=y while not (a>=x and b>=x and c>=x): if cnt%3==0: a = b+c-1 elif cnt%3==1: b = a+c-1 else: c = a+b-1 cnt += 1 print(cnt)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; inline int read(int x = 0, int f = 1, char ch = '0') { while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return f * x; } const int N = 100000 + 5; int x, y; int a, b, c; int main() { cin >> y >> x; a = b = c = x; int cnt = 0; while (c <= y) { ++cnt; a = b; b = c; c = a + b - 1; } printf("%d\n", cnt + 2); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y = map(int, raw_input().split(" ")) #print x,y tup = [y,y,y] goal = [x,x,x] count = 0 while tuple(tup) != tuple(goal): tup = sorted(tup) tup[0] = min(tup[1] + tup[2] - 1, x) count += 1 print count
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int a = y, b = y, c = y; int op = 1; a = b + c - 1; int flag = 0; if (a >= x) { a = x; flag = 1; } while (flag == 0) { if (op % 3 == 1) { b = a + c - 1; if (b >= x) { b = x; flag = 1; } op++; } else if (op % 3 == 2) { c = a + b - 1; if (c >= x) { c = x; flag = 1; } op++; } else { a = b + c - 1; if (a >= x) { a = x; flag = 1; } op++; } } if (a != x) op++; if (b != x) op++; if (c != x) op++; cout << op << endl; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class Luck{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); int[] A=new int[3]; A[0]=y; A[1]=y; A[2]=y; int res=0; while(true){ A[0]=(A[1]+A[2]-1); Arrays.sort(A); res+=1; if(A[0]>=x){ break; } } System.out.println(res); sc.close(); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; import java.math.*; import java.io.*; import java.text.*; public class A { static class Node implements Comparable<Node>{ int x; long w; int id; public Node(int x,long w,int id){ this.x=x; this.w=w; this.id=id; } public int compareTo(Node c){ int i=Long.compare(this.w,c.w); return i; } @Override public boolean equals(Object o){ if(o instanceof Node){ Node c = (Node)o; return true; } return false; } } //public static PrintWriter pw; public static PrintWriter pw = new PrintWriter(System.out); public static void solve() throws IOException { // pw=new PrintWriter(new FileWriter("C:\\Users\\shree\\Downloads\\small_output_in")); FastReader sc = new FastReader(); int x=sc.I(); int y=sc.I(); int t=x;x=y; y=t; int a[]={x,x,x}; int ans=0; while(true){ if(a[0]==y) break; a[0]=Math.min(a[1]+a[2]-1,y); ans++; Arrays.sort(a); } pw.println(ans); pw.close(); } public static void main(String[] args) { new Thread(null, new Runnable() { public void run() { try { solve(); } catch (Exception e) { e.printStackTrace(); } } }, "1", 1 << 26).start(); } static BufferedReader br; static long M = (long) 1e9 + 7; static class FastReader { StringTokenizer st; public FastReader() throws FileNotFoundException { //br=new BufferedReader(new FileReader("C:\\Users\\shree\\Downloads\\B-small-practice.in")); br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int I() { return Integer.parseInt(next()); } long L() { return Long.parseLong(next()); } double D() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public boolean hasNext() throws IOException { while (st == null || !st.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return false; } st = new StringTokenizer(s); } return true; } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y=map(int,input().split()) a=b=c=y turn=0 while(1): if(a>=x and b>=x and c>=x): print(turn) break elif(turn%3==0): c=a+b-1 elif(turn%3==1): b=a+c-1 else: a=b+c-1 turn+=1
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; long long n, cnt, x, y, arr[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> x >> y; for (long long i = 0; i <= 2; i++) arr[i] = y; while (arr[0] != x) { arr[0] = min(arr[1] + arr[2] - 1, x); sort(arr, arr + 3); cnt++; } cout << cnt << endl; cin >> n; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws java.lang.Exception { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); PrintWriter out=new PrintWriter(System.out); int x,y,ans,all,i; StringTokenizer st=new StringTokenizer(in.readLine().trim()); x=Integer.parseInt(st.nextToken()); y=Integer.parseInt(st.nextToken()); Integer[] a=new Integer[3]; for(i=0;i<3;i++) a[i]=y; all=0; for(i=0;i<3;i++) { if(a[i]==x) all++; } ans=0; while(all<3) { Arrays.sort(a); a[0]=Math.min(a[1]+a[2]-1,x); all=0; for(i=0;i<3;i++) { if(a[i]==x) all++; //out.print(a[i]+" "); } ans++; /* ++loop; if(loop>10) { break; } out.println(); */ } out.println(ans); out.close(); out.flush(); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int x, y; int a[5], ans; int main() { scanf("%d%d", &x, &y); int z = x + y; x = min(x, y); y = z - x; a[1] = a[2] = a[3] = x; for (; a[1] != y || a[2] != y || a[3] != y; ++ans) { sort(a + 1, a + 3 + 1); a[1] = min(a[2] + a[3] - 1, y); } cout << ans << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.StringTokenizer; public class CF712C { public static void main(String args[]){ InputReader in = new InputReader(System.in); //OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(System.out); int o,f; o=in.nextInt(); f=in.nextInt(); int ar[]=new int[3]; ar[0]=f; ar[1]=f; ar[2]=f; int ans=0; while(ar[0]!=o){ ar[0]=Math.min((ar[1]+ar[2]-1), o); Arrays.sort(ar); ans++; } out.println(ans); out.close(); } static class Pair implements Comparable<Pair> { int u; int v; BigInteger bi; public Pair(int u, int v) { this.u = u; this.v = v; } public int hashCode() { int hu = (int) (u ^ (u >>> 32)); int hv = (int) (v ^ (v >>> 32)); return 31 * hu + hv; } public boolean equals(Object o) { Pair other = (Pair) o; return u == other.u && v == other.v; } public int compareTo(Pair other) { return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v); } public String toString() { return "[u=" + u + ", v=" + v + "]"; } } public static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } static long modulo(long a,long b,long c) { long x=1; long y=a; while(b > 0){ if(b%2 == 1){ x=(x*y)%c; } y = (y*y)%c; // squaring the base b /= 2; } return x%c; } static long gcd(long x, long y) { if(x==0) return y; if(y==0) return x; long r=0, a, b; a = (x > y) ? x : y; // a is greater number b = (x < y) ? x : y; // b is smaller number r = b; while(a % b != 0) { r = a % b; a = b; b = r; } return r; } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream inputstream) { reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine(){ String fullLine=null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine=reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int x, y; int a[3]; int main() { cin >> x >> y; int t = 0; for (int i = 0; i <= 2; i++) a[i] = y; while (a[0] != x) { t++; sort(a, a + 3); a[0] = a[1] + a[2] - 1; a[0] = min(x, a[0]); } cout << t + 2; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int x, y; while (~scanf("%d%d", &y, &x)) { int a[5]; a[0] = a[1] = a[2] = x; int res = 0; while (true) { if (a[0] == a[1] && a[0] == a[2] && a[0] == y) break; sort(a, a + 3); a[0] = min(y, a[2] + a[1] - 1); res++; } cout << res << endl; } }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
def solve(x, y): A = [y]*3 k = 0 while A[0] != x: k += 1 A[0] = min(A[1] + A[2] - 1, x) A.sort() return k x, y = map(int, input().split()) print(solve(x, y))
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int x, y; int ans = 1000000000; int solve(int a, int b, int c) { if (c > a) swap(a, c); if (b > a) swap(a, b); if (c > b) swap(c, b); if (a == b && b == c && c == x) return 0; return solve(a, b, min(x, a + b - 1)) + 1; } int main() { ios_base::sync_with_stdio(0); cin >> x >> y; cout << solve(y, y, y) << endl; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; import java.io.*; public class CF712C{ public static int index; public static void main(String[] args)throws Exception { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int n = in.nextInt() , m =in.nextInt(); int x = Math.min(n,m), y = Math.max(n,m), cnt = 0; Integer a[] = {x,x,x}; while(!check(a, y)){ int r = a[1] + a[2]-1; if(r > y) r = y; a[0] = r; Arrays.sort(a); cnt++; } pw.println(cnt); pw.close(); } static boolean check(Integer []a, int m){ if(a[0] == m && a[1] == m && a[2] == m) return true; else return false; } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next()throws Exception { while (tokenizer == null || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } public String nextLine()throws Exception { String line = null; tokenizer = null; line = reader.readLine(); return line; } public int nextInt()throws Exception { return Integer.parseInt(next()); } public double nextDouble() throws Exception{ return Double.parseDouble(next()); } public long nextLong()throws Exception { return Long.parseLong(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class Main { public static void main(String []args){ Scanner sc=new Scanner (System.in); int x=sc.nextInt();int y=sc.nextInt(); int a=y,b=y,c=y; long count=0; while(a!=x||b!=x||c!=x){ c=a+b-1<x?a+b-1:x; int temp=c; c=b;b=a;a=temp; count++; } System.out.println(count); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class DeEvolution { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int y1 = y; int y2 = y; int y3 = y; int count = 0; //int temp = y3; while(y1!=x || y2!=x || y3!=x){ int temp; if(y1<=y2 && y1<=y3) temp = y1; else if(y2<=y3 && y2<=y1) temp = y2; else temp = y3; if(temp==y1){ if(y1<x){ y1 = y2 + y3 -1; count++; //System.out.println(count + " " +y1); if(y1>x) y1=x; } } else if(temp==y2){ if(y2<x){ y2 = y1 + y3 -1; count++; //System.out.println(count + " " + y2); if(y2>x) y2=x; } } else if(temp==y3){ if(y3<x){ y3 = y2 + y1 -1; count++; //System.out.println(count + " " + y3); if(y3>x) y3=x; } } } System.out.println(count); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int ans, x; void func(int a[]) { int t = 0; for (int i = 0; i < 3; i++) { t += (a[i] == x); } if (t > 0) { ans += 3 - t; return; } a[0] = min(x, a[1] + a[2] - 1); sort(a, a + 3); ans++; func(a); } int main() { int y; ans = 0; cin >> x >> y; int a[3]; a[0] = a[1] = a[2] = y; func(a); cout << ans; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; import java.io.*; /** * * @author umang */ public class C712 { public static int mod = 1000000007; public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int x = in.nextInt(); int y = in.nextInt(); int a =y,b=y,c=y; int count=0; while(true){ if(a>=x && b>=x && c>=x) break; if(count%3==0){ a = (b+c)-1; count++; } else if(b<x && count%3==1){ b = (a+c)-1; count++; } else if(c<x){ c = (a+b)-1; count++; } } w.println(count); w.close(); } static class Pair{ int c; int x; int y; public Pair(int x,int y,int c){ this.x=x; this.y=y; this.c=c; } } static class CompareCost implements Comparator{ @Override public int compare(Object t, Object t1) { Pair p1 = (Pair)t; Pair p2 = (Pair)t1; if(p1.c<p2.c){ return -1; } else if(p1.c>p2.c){ return 1; } else return 0; } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int toNumber(string s) { int Number; if (!(istringstream(s) >> Number)) Number = 0; return Number; } string toString(int number) { ostringstream ostr; ostr << number; return ostr.str(); } int main() { int x, y; cin >> x >> y; int a[3]; for (int i = 0; i < (int)(3); i++) { a[i] = y; } int cant = 0; while (a[0] < x) { int p = a[1] + a[2] - 1; int a1 = a[1]; int a2 = a[2]; a[0] = a1; a[1] = a2; a[2] = p; cant++; } cout << cant << endl; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y1, i = 0; cin >> x >> y1; int y[3]; y[0] = y[1] = y[2] = y1; while (y[0] != x || y[1] != x || y[2] != x) { y[i % 3] = min(y[(i + 1) % 3] + y[(i + 2) % 3] - 1, x); i++; } cout << i << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
from math import * def solve(a,b): if(a[0]==b): return 0 else: return solve([a[1],a[2],min(b,a[1]+a[2]-1)],b)+1 a,b=(int(z) for z in input().split()) if a>b: a,b=b,a print(solve([a,a,a],b))
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; /** */ public class Main712C { public static void main(String[] args) { run(System.in, System.out); } public static void run(InputStream in, PrintStream out) { try (Scanner sc = new Scanner(in)) { int x = sc.nextInt(); int y = sc.nextInt(); int[] l = new int[3]; l[0] = y; l[1] = y; l[2] = y; int cpt = 0; int idx = 0; while (true) { if (l[0] == l[1] && l[1] == l[2] && l[2] == x) break; l[idx] = min(x, l[(idx + 1) % 3] + l[(idx + 2) % 3] - 1); cpt++; idx = (idx + 1) % 3; } out.print(cpt); } } public static int min(int a, int b) { return a < b ? a : b; } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.StringTokenizer; import java.math.BigInteger; public class triangles { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[]) { FastReader s=new FastReader(); int x=s.nextInt(); int y=s.nextInt(); int a[]=new int[3]; int f=0; Arrays.fill(a,y); int t=0; while(f!=1) { if(a[0]!=x) { int w=(a[1]+a[2])-1; if(w>x) { a[0]=x; } else{ a[0]=w; } t++; } if(a[1]!=x) { int h=(a[0]+a[2])-1; if(h>x) { a[1]=x; } else a[1]=h; t++; } if(a[2]!=x) { int kk=(a[0]+a[1])-1; if(kk>x) { a[2]=x; } else{ a[2]=kk; } t++; } if(a[0]==x && a[1]==x && a[2]==x) { f=1; } } System.out.println(t); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.Scanner; /** * Link: * http://codeforces.com/problemset/problem/712/C */ /** * C. ΠœΠ΅ΠΌΠΎΡ€ΠΈ ΠΈ Π΄Π΅Π²ΠΎΠ»ΡŽΡ†ΠΈΡ * ΠœΠ΅ΠΌΠΎΡ€ΠΈ ΠΈΠ·ΡƒΡ‡Π°Π΅Ρ‚ Π΄Π΅Π²ΠΎΠ»ΡŽΡ†ΠΈΡŽ Ρ€Π°Π·Π»ΠΈΡ‡Π½Ρ‹Ρ… ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ², Π² Π΄Π°Π½Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΎΠ². Она Π½Π°Ρ‡ΠΈΠ½Π°Π΅Ρ‚ с равностороннСго * Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° со сторонами, Ρ€Π°Π²Π½Ρ‹ΠΌΠΈ x, ΠΈ Ρ…ΠΎΡ‡Π΅Ρ‚ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ нСсколько ΠΎΠΏΠ΅Ρ€Π°Ρ†ΠΈΠΉ Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ равносторонний * Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ со сторонами y. * Π—Π° ΠΎΠ΄Π½Ρƒ сСкунду ΠœΠ΅ΠΌΠΎΡ€ΠΈ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π΄Π»ΠΈΠ½Ρƒ Ρ€ΠΎΠ²Π½ΠΎ ΠΎΠ΄Π½ΠΎΠΉ стороны Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΎΠ½ оставался * Π½Π΅Π²Ρ‹Ρ€ΠΎΠΆΠ΄Π΅Π½Π½Ρ‹ΠΌ Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΎΠΌ (Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠΎΠΌ Π½Π΅Π½ΡƒΠ»Π΅Π²ΠΎΠΉ ΠΏΠ»ΠΎΡ‰Π°Π΄ΠΈ). Π’ любой ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ всС стороны Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° * Π΄ΠΎΠ»ΠΆΠ½Ρ‹ ΠΈΠΌΠ΅Ρ‚ΡŒ Ρ†Π΅Π»ΠΎΡ‡ΠΈΡΠ»Π΅Π½Π½ΡƒΡŽ Π΄Π»ΠΈΠ½Ρƒ. * Π—Π° ΠΊΠ°ΠΊΠΎΠ΅ минимальноС количСство сСкунд ΠœΠ΅ΠΌΠΎΡ€ΠΈ смоТСт ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ равносторонний Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ с Π΄Π»ΠΈΠ½ΠΎΠΉ стороны y? * Π’Ρ…ΠΎΠ΄Π½Ρ‹Π΅ Π΄Π°Π½Π½Ρ‹Π΅ * Π’ СдинствСнной строкС Π²Ρ…ΠΎΠ΄Π½Ρ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… записаны Π΄Π²Π° Ρ†Π΅Π»Ρ‹Ρ… числа x ΠΈ y (3 ≀ y < x ≀ 100 000) β€” ΠΈΠ·Π½Π°Ρ‡Π°Π»ΡŒΠ½Π°Ρ ΠΈ ТСлаСмая * Π΄Π»ΠΈΠ½Π° всСх сторон Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° соотвСтствСнно. * Π’Ρ‹Ρ…ΠΎΠ΄Π½Ρ‹Π΅ Π΄Π°Π½Π½Ρ‹Π΅ * Π’Ρ‹Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΎΠ΄Π½ΠΎ Ρ†Π΅Π»ΠΎΠ΅ число β€” минимальноС количСство сСкунд, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ потрСбуСтся ΠœΠ΅ΠΌΠΎΡ€ΠΈ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ * равносторонний Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊ со стороной y, Ссли ΠΎΠ½Π° Π½Π°Ρ‡ΠΈΠ½Π°Π΅Ρ‚ с равностороннСго Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° со стороной x. */ public class C { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(), y = sc.nextInt(); // Π‘Ρ‡ΠΈΡ‚Ρ‹Π²Π°Π΅ΠΌ Ρ…-тСкущая Π΄ΠΈΠ»Π½Π°, Ρƒ-ТСлаСмая int a, b, c, count = 0; a = b = c = y; // a, b, c - стороны Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° while(!(a >= x && b >= x && c >= x)){ // ΠΏΠΎΠ΄Ρ…ΠΎΠ΄ Π·Π°ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ Π½Π΅ Π² ΡƒΠΌΠ΅Π½ΡŒΡˆΠ½ΠΈΠΈ сторон ΠΈΠΌΠ΅ΡŽΡ‰Π΅Π³ΠΎΡΡ Ρ‚Ρ€Π΅ΡƒΠ³ΠΎΠ»ΡŒΠ½ΠΈΠΊΠ° Π΄ΠΎ ΠΆΠ΅Π»Π°Π΅ΠΌΠΎΠ³ΠΎ, count++; // Π° Π² ΡƒΠ²Π΅Π»ΠΈΡ‡Π΅Π½ΠΈΠΈ ΠΆΠ΅Π»Π°Π΅ΠΌΠΎΠ³ΠΎ Π΄ΠΎ Ρ‚Π΅ΠΊΡƒΡ‰Π΅Π³ΠΎ, ΠΏΡ€ΠΈΡ‡Π΅ΠΌ каТдая сторона ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½ΠΎ увСличиваСтся // максимально. УсловиС Π²Ρ‹Ρ…ΠΎΠ΄Π° ΠΊΠΎΠ³Π΄Π° каТдая сторона Π±ΡƒΠ΄Π΅Ρ‚ >= Ρ‚Π΅ΠΊΡƒΡ‰Π΅ΠΉ if(count % 3 == 1){ // Π½Π° ΠΊΠ°ΠΆΠ΄ΠΎΠΌ шагС ΡƒΠ²Π΅Π»ΠΈΡ‡ΠΈΠ²Π°Π΅ΠΌ Ρ€Π°Π·Π½Ρ‹Π΅ стороны a = b + c - 1; } if(count % 3 == 2){ b = a + c - 1; } if(count % 3 == 0){ c = a + b - 1; } } System.out.println(count); sc.close(); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #-------------------game starts now----------------------------------------------------- x,y=map(int,input().split()) a=y b=y c=y t=1 ans=0 while(True): if a==x and b==x and c==x: break ans+=1 if t==1: a=b+c-1 if a>x: a=x elif t==2: b=a+c-1 if b>x: b=x else: c=b+a-1 if c>x: c=x t=(t+1)%3 print(ans)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * Created by birukoudzmitry on 08.06.16. */ public class C { // 6,6,6 -> 3,6,6 -> public static void main(String[] args){ MyScanner in = new MyScanner(); int x = in.nextInt(); int y = in.nextInt(); int side = Math.min(x,y); int target = Math.max(x,y); int a = side; int b = side; int c = side; int t = 0; while(a!=target||b!=target||c!=target){ if(a<=b&&a<=c){ a = Math.min(target,b+c-1); }else if(b<=a&&b<=c){ b = Math.min(target,a+c-1); }else{ c = Math.min(target,a+b-1); } t++; } System.out.println(t); } // -----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // -------------------------------------------------------- }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class R370D2P3 { public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(bf.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); // try just working greedily int a = y, b = y, c = y; int t = 0; while (a < x || b < x || c < x) { // System.out.println(a + ", " + b + ", " + c); // assume a < b < c // inflate a, so it becomes largest int newC = Math.min(x, b + c - 1); int newB = c; int newA = b; a = newA; b = newB; c = newC; t++; } System.out.println(t); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.lang.*; import java.io.*; import java.util.*; public class Evolution { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } } class TaskA { public void solve(InputReader in, PrintWriter out) { int[] a = new int[3]; int x = in.nextInt(), y = in.nextInt(); int sum, tmp, mx, v; int ans = 0; a[0] = a[1] = a[2] = y; while (!(a[0]==x && a[1]==x && a[2]==x)) { sum = a[0] + a[1] + a[2]; v = a[0]<a[1] ? 0:1; v = a[2]<a[v] ? 2:v; tmp = (a[0]+a[1]+a[2]) - a[v] - 1; tmp = tmp>x ? x:tmp; a[v] = tmp; ++ans; } out.println(ans); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer==null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { long x, y, i, a, b, c, p = 0; cin >> x >> y; a = y; b = y; c = y; while (a != x || b != x || c != x) { if (a != x) { a = b + c - 1; ++p; } if (a > x) a = x; if (b != x) { b = a + c - 1; ++p; } if (b > x) b = x; if (c != x) { c = a + b - 1; ++p; } if (c > x) c = x; } cout << p; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; long long x, y; long long a[5]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> x >> y; a[1] = y, a[2] = y, a[3] = y; for (long long i = 1;; i++) { a[1] = min(x, a[2] + a[3] - 1); sort(a + 1, a + 4); if (a[1] == x) { cout << i; return 0; } } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, a, b, c, cn = 0; cin >> m >> n; a = n; b = n; c = n; while (a < m || b < m || c < m) { if (c < m) { c = a + b - 1; cn++; } if (a < m) { cn++; a = b + c - 1; } if (b < m) { cn++; b = a + c - 1; } } cout << cn; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import sys a,b = map(int,sys.stdin.readline().split()) la = [min(a,2*b-1),b,b] cnt = 1 while 1<2: la[la.index(min(la))]=min(sum(la)-min(la)-1,a) cnt+=1 if(la==[2*b-1,a,a]): cnt+=1 break elif(la==[a,a,a]): break print(cnt)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
# -*- coding: utf-8 -*- """ Created on Sun Sep 11 21:29:34 2016 @author: sigmoidguo """ import sys, math x, y = map(int, raw_input().split()) a = b = c = y step = 0 #for i in range(7): while True: ## stop condition if a == x and b == x and c == x: print step sys.exit(0) a1 = min(x, b + c - 1) a = b b = c c = a1 step += 1 #print a, b, c
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main(void) { int i, x, y; cin >> x >> y; int a[3]; for (i = 0; i <= (int)(3) - 1; i++) a[i] = y; int ans = 0; for (; a[0] < x; ans++) { a[0] = min(x, a[1] + a[2] - 1); sort(a, a + 3); } cout << ans << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { vector<int> edge(3); int target(0), curr(0); while (cin >> target >> curr) { fill(edge.begin(), edge.end(), curr); int res(0); while (true) { bool flag = true; for (int i = 0; i < 3; ++i) { if (edge[i] != target) { flag = false; } } if (flag) { break; } sort(edge.begin(), edge.end()); if (edge[1] + edge[2] - 1 < target) { edge[0] = edge[1] + edge[2] - 1; } else { edge[0] = target; } ++res; } cout << res << endl; } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
//package round370; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class C { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int x = ni(), y = ni(); int a = y, b = y, c = y; int step = 0; while(!(a == x && b == x && c == x)){ c = Math.min(x, a+b-1); int d = a; a = b; b = c; c = d; step++; } out.println(step); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new C().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.Scanner; public class memoryanddeevolution { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); String data = s.nextLine(); int from = Integer.parseInt(data.split(" ")[0]); int to = Integer.parseInt(data.split(" ")[1]); int secs = 1; while (from >= ((f(secs) * to) - g(secs))) { secs++; } System.out.println(secs); } public static int f(int i) { if (i == 0) { return 0; } if (i == 1) { return 1; } return f(i - 1) + f(i - 2); } public static int g(int i) { int sum = 0; for (int j = 0; j < i - 1; j++) { sum += f(j); } return sum; } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x, y = map(int, raw_input().split()) if y*2 > x : print 3 elif y*2 == x : print 4 else : ls = [y, y, y] count = 0 while True : if min(ls) == x : break count += 1 ls[count%3] = min(x, ls[(count+1)%3] + ls[(count+2)%3] - 1) print count
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long res, f, x, y, l1, l2, l3, ma; scanf("%lld %lld", &x, &y); l1 = l2 = l3 = y; res = 0; f = 1; while (l1 < x || l2 < x || l3 < x) { res++; if (f == 1) { l1 = l3 + l2 - 1; f++; } else if (f == 2) { l2 = l3 + l1 - 1; f++; } else if (f == 3) { l3 = l1 + l2 - 1; f = 1; } } printf("%lld\n", res); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; public class MemoryAndDeEvolution { static long countTime = 0; public static void evlove(long a1,long b1,long c1, long s2, long s1){ if(s2 == s1) return; if(s1>=s2*2){ a1 = s2*2-1; } else a1 = s1; countTime++; if(!(a1+b1==c1 || b1+c1==a1 || a1+c1==b1)){ while(b1!=s1 || c1!=s1 || a1!=s1){ if(b1!=s1){ if((b1 = Math.abs(c1+a1-1))>s1) b1 = s1; countTime++; } if(c1!=s1){ if((c1 = Math.abs(b1+a1-1))>s1) c1 = s1; countTime++; } if(a1!=s1){ if((a1 = Math.abs((b1+c1)-1))>s1) a1 = s1; countTime++; } } } } public static void main(String[]args){ InputReader reader = new InputReader(System.in); PrintWriter writer = new PrintWriter(System.out); long s1 = reader.nextInt(); long s2 = reader.nextInt(); long a1 = s1,b1 = s1,c1 = s1; long a2 = s2,b2 = s2,c2 = s2; if(s1>s2) evlove(a2, b2, c2, s2,s1); else evlove(a1, b1, c1, s1, s2); writer.println(countTime); writer.close(); } public static class InputReader{ private BufferedReader reader; private StringTokenizer tokens; public InputReader(InputStream stream) { // TODO Auto-generated constructor stub reader = new BufferedReader(new InputStreamReader(stream), 67854); tokens = null; } public String next(){ while(tokens == null || !tokens.hasMoreTokens()){ try { tokens = new StringTokenizer(reader.readLine()); } catch (IOException e) { // TODO Auto-generated catch block throw new RuntimeException(e); } } return tokens.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; public final class round_370_c { static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static FastScanner sc=new FastScanner(br); static PrintWriter out=new PrintWriter(System.out); public static void main(String args[]) throws Exception { int n=sc.nextInt(),m=sc.nextInt();boolean now=true;int[] a=new int[3];Arrays.fill(a,m);int cnt=0; while(now) { now=false;cnt++;int ptr=-1;int[] b=a.clone();int min=n; for(int i=0;i<3;i++) { if(a[i]<min) { min=a[i];ptr=i; } } int low=1,high=n-a[ptr]; while(low<high) { int mid=(low+high+1)>>1,curr=a[ptr]+mid;b[ptr]=curr; if(b[0]<b[1]+b[2] && b[2]<b[0]+b[1] && b[1]<b[0]+b[2]) { low=mid; } else { high=mid-1; } } a[ptr]+=low; for(int i=0;i<3;i++) { if(a[i]<n) { now=true;break; } } //out.println(Arrays.toString(a)); } out.println(cnt);out.close(); } } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) { this.in = in; } public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public String next() throws Exception { return nextToken().toString(); } public int nextInt() throws Exception { return Integer.parseInt(nextToken()); } public long nextLong() throws Exception { return Long.parseLong(nextToken()); } public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int edge[4], sum; int st, aim; int main() { cin >> aim >> st; int count = 0; edge[3] = edge[1] = edge[2] = st; sum = st * 3; while (sum != aim * 3) { for (int i = 1; i <= 3; i++) { if (edge[i] == aim) continue; sum -= edge[i]; edge[i] = min(aim, sum - 1); sum += edge[i]; count++; } } cout << count << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; vector<int> kek; kek.push_back(y); kek.push_back(y); kek.push_back(y); int count = 0; if (x == y) cout << 0 << endl; else if (x > y) { kek[1] = min(x, kek[0] + kek[2] - 1); count++; while (true) { kek[0] = min(x, kek[2] + kek[1] - 1); count++; if (kek[0] == x && kek[1] == x && kek[2] == x) break; sort(kek.begin(), kek.end()); } cout << count << endl; } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; bool flag = false; std::vector<int> v; v.push_back(b); v.push_back(b); v.push_back(b); do { flag = true; sort(v.begin(), v.end()); if (v[0] == a && v[1] == a && v[2] == a) { flag = false; } else { ans++; v[0] = min(a, v[1] + v[2] - 1); } } while (flag); cout << ans << endl; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y=map(int,input().split()) a,b,c=y,y,y ans=0 while (a,b,c)<(x,x,x,): new=b+c-1 a,b,c=b,c,new ans+=1 print(ans)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int a=y; int b=y; int c=y; int turns = 0; while(a!=x||b!=x||c!=x) { if(a<=b&&a<=c){ a = Math.min(b+c-1,x); }else if(b<=c&&b<=a){ b = Math.min(a+c-1,x); }else if(c<=b&&c<=a){ c = Math.min(a+b-1,x); } // System.out.println(a+":"+b+":"+c); turns++; } System.out.println(turns); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int x = in.nextInt(); int y = in.nextInt(); int[] a = new int[3]; Arrays.fill(a, y); int ans = 0; Arrays.sort(a); while (a[0] < x) { a[0] = a[1] + a[2] - 1; Arrays.sort(a); ans++; } out.println(ans); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf("%d %d", &x, &y); int tr[3] = {y, y, y}; int ans = 0; while (tr[0] != x || tr[1] != x || tr[2] != x) { for (int i = 0; i < 3; i += 1) { if (tr[i] == x) continue; int nxt = tr[(i + 1) % 3]; int prv = tr[(i - 1 + 3) % 3]; int req = min(x, nxt + prv - 1); if (req != tr[i]) { tr[i] = req; ++ans; } } } printf("%d\n", ans); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int x, y; int proc(vector<int> v) { sort(v.begin(), v.end()); if (v[0] == x) return 0; v[0] = min(x, v[1] + v[2] - 1); return 1 + proc(v); } int main() { scanf("%d%d", &x, &y); vector<int> v(3, y); printf("%d\n", proc(v)); }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; void solve() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int x, y; long long k = 0; cin >> x >> y; int a[3] = {y, y, y}; while (a[0] != x || a[1] != x || a[2] != x) { sort(a, a + 3); a[0] = min(x, a[2] + a[1] - 1); k++; } cout << k; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t; t = 1; while (t--) { solve(); } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.IOException; import java.util.InputMismatchException; public class MemoryAndDeEvolution { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int X = sc.nextInt(); int Y = sc.nextInt(); int[] arr = new int[32]; arr[0] = arr[1] = arr[2] = Y; for (int i = 3; ; i++) { arr[i] = arr[i - 1] + arr[i - 2] - 1; if (arr[i] >= X) { System.out.println(i); return; } } } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
y, x = map(int, input().split()) arr = [x, x, x] count = 0 while True: if arr[0] >= y: break count += 1 arr[0] = min(y, arr[1] + arr[2] - 1) arr.sort() print(count)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y, count = 0; scanf("%d %d", &x, &y); if (x > y) swap(x, y); int x1 = x, x2 = x, x3 = x; while (x1 != y || x2 != y || x3 != y) { x1 = x2 + x3 - 1; swap(x1, x2); swap(x2, x3); if (x3 > y) x3 = y; count++; } printf("%d\n", count); }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; static int x, y; int main() { while (scanf("%d%d", &y, &x) != EOF) { vector<int> v = {x, x, x}; int ans = 0; while (true) { if (v[0] == y && v[1] == y && v[2] == y) break; if (v[1] == y) { v[0] = y; } else if (v[1] + v[2] - 1 < y) v[1] += v[2] - 1; else v[1] = y; ++ans; sort(v.begin(), v.end()); } printf("%d\n", ans); } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; /** * This program prints a single integer β€” the minimum number * of seconds required for Memory to obtain the equilateral * triangle of side length y if it starts with the equilateral * triangle of side length x. * * @author Group 5 * @version 1.00 2016/10/26 */ public class MemoryAndDeEvolution { public static void main(String args[]) { Scanner in = new Scanner(System.in); int x; int y; x = in.nextInt(); y = in.nextInt(); int term = y; int prevTerm = y; int ans = 1; while(term<x) { int temp = term; term = term+prevTerm-1; prevTerm = temp; ans++; } System.out.print(++ans); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int inf_int = 2e9; long long inf_ll = 2e18; const double pi = 3.1415926535898; template <typename T, typename T1> void prin(vector<pair<T, T1> >& a) { for (int i = 0; i < a.size(); i++) { cout << a[i].first << " " << a[i].second << "\n"; } } template <typename T, typename T1> void prin(set<pair<T, T1> >& a) { for (auto it = a.begin(); it != a.end(); it++) { cout << it->first << " " << it->second << "\n"; } } template <typename T> void prin(vector<T>& a) { for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i < a.size() - 1) cout << " "; else cout << "\n"; } } template <typename T> void prin(set<T>& a) { for (auto it = a.begin(); it != a.end(); it++) { cout << *it << " "; } } template <typename T> void prin_new_line(vector<T>& a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << "\n"; } } template <typename T, typename T1> void prin_new_line(vector<pair<T, T1> >& a) { for (int i = 0; i < a.size(); i++) { cout << a[i].first << " " << a[i].second << "\n"; } } int sum_vec(vector<int>& a) { int s = 0; for (int i = 0; i < a.size(); i++) { s += a[i]; } return s; } template <typename T> T max(vector<T>& a) { T ans = a[0]; for (int i = 1; i < a.size(); i++) { ans = max(ans, a[i]); } return ans; } template <typename T> T min(vector<T>& a) { T ans = a[0]; for (int i = 1; i < a.size(); i++) { ans = min(ans, a[i]); } return ans; } template <typename T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> T max(T a, T b, T c) { return max(a, max(b, c)); } bool debug = 0; const int maxn = 2e6 + 100; long long mod = 1e4 + 7; inline int abs(int x) { if (x > 0) return x; return -x; } int x, y; bool ok(int a, int b, int c) { if (a + b > c && a + c > b && b + c > a) { return true; } return false; } int dfs(int a, int b, int c) { if (a == x) { return 0; } int l = a + 1, r = x; int ans = l; while (l <= r) { int m = (l + r) >> 1; if (ok(m, b, c)) { ans = m; l = m + 1; } else { r = m - 1; } } vector<int> d; d.push_back(ans); d.push_back(b); d.push_back(c); sort(d.begin(), d.end()); return 1 + dfs(d[0], d[1], d[2]); } void solve() { cin >> x >> y; cout << dfs(y, y, y); } int main() { if (!debug) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int t = 1; while (t--) solve(); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> template <class T> inline void rd(T &x) { char c = getchar(); x = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } } using namespace std; const int N = 111111; const int MOD = 1e9 + 7; int a[3]; int main() { int x, y; scanf("%d%d", &x, &y); a[0] = y, a[1] = y, a[2] = y; int t = 0; while (a[0] != x) { a[0] = a[1] + a[2] - 1; a[0] = min(x, a[0]); t++; sort(a, a + 3); } cout << t << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.StringTokenizer; public class _712_C_Memory_and_DeEvolution { public static void main(String[] args) throws Exception { InputStream inputStream = (args.length <= 0) ? System.in : new FileInputStream(args[0]); OutputStream outputStream = (args.length <= 1) ? System.out : new FileOutputStream(args[1]); Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); if (args.length == 0) solver.solve(1, in, out); else { int T = in.nextInt(); for (int t = 1; t <= T; t++) { out.println("Case " + t + ":"); solver.solve(t, in, out); } } out.close(); } static class Scanner { public BufferedReader reader; public StringTokenizer tokenizer; public Scanner(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class Solver { void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); int o = in.nextInt(); int[] a = new int[]{o, o, o}; int c = 0; for (int i = 0; i < n * 3; i++) { c++; int tmp = Math.min(n, a[1] + a[2] - 1); a[0] = a[1]; a[1] = a[2]; a[2] = tmp; if (a[1] == n && a[2] == n) break; } if (a[0] != n) c++; out.println(c); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
""" Python 3 compatibility tools. """ from __future__ import division, print_function import itertools import sys import os from io import BytesIO, IOBase if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip def is_it_local(): script_dir = str(os.getcwd()).split('/') username = "dipta007" return username in script_dir def READ(fileName): if is_it_local(): sys.stdin = open(f'./{fileName}', 'r') # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") if not is_it_local(): sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion def input1(type=int): return type(input()) def input2(type=int): [a, b] = list(map(type, input().split())) return a, b def input3(type=int): [a, b, c] = list(map(type, input().split())) return a, b, c def input_array(type=int): return list(map(type, input().split())) def input_string(): s = input() return list(s) ############################################################## def main(): x, y = input2() if x > y: x, y = y, x arr = [x, x, x] cnt = 0 while arr[0] != y: rem = arr[1] + arr[2] k = min(y, rem-1) arr[0] = k arr.sort() cnt += 1 # print(arr) print(cnt) pass if __name__ == '__main__': # READ('in.txt') main()
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.Arrays; import java.util.Scanner; /** * Created by Jaydeep on 9/25/2016. */ public class Triangle { public static void main(String[] args) { long count = 0; Scanner in = new Scanner(System.in); long[] triangle = new long[3]; long goal = in.nextInt(); long first = in.nextInt(); Arrays.fill(triangle, first); int turn = 0; while (!(triangle[0] == goal && triangle[1] == goal && triangle[2] == goal)) { if (turn == 0) { if (triangle[1] + triangle[2] > goal) { triangle[0] = goal; } else { triangle[0] = triangle[1] + triangle[2] - 1; } } else if (turn == 1) { if (triangle[0] + triangle[2] > goal) { triangle[1] = goal; } else { triangle[1] = triangle[2] + triangle[0] - 1; } } else { if (triangle[0] + triangle[1] > goal) { triangle[2] = goal; } else { triangle[2] = triangle[1] + triangle[0] - 1; } } turn = (turn + 1) % 3; count++; } System.out.println(count); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
line1=input().split() x=int(line1[0]) y=int(line1[1]) a,b,c=y,y,y steps=0 while (a<x or b<x or c<x): a=b+c-1 steps+=1 a,b,c=min(a,b,c), a+b+c-max(a,b,c)-min(a,b,c), max(a,b,c) print (steps)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x, y = map(int, input().split()) a, v = [y] * 3, 0 while a[0] < x: a[0] = min(x, a[1] + a[2] - 1) a.sort() v += 1 print(v)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 55; int let[27]; int main() { int n, ans = 0, x, y, z, m; cin >> n >> m; x = y = z = m; while (1) { if (x == y && y == z && z == n) break; if (y >= z) swap(y, z); if (x >= y) swap(x, y); x = min(n, z + y - 1); ans++; } cout << ans; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
from sys import stdin x, y = map(int, stdin.readline().split()) ans, cur = 0, [y, y, y] while not (cur[0] == cur[1] == cur[2] == x): ans += 1 cur[0] = min(x, (cur[1] + cur[2]) - 1) cur.sort() print(ans)
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int a = y, b = y, c = y; int co = 0; while (true) { if (a >= x && b >= x && c >= x) { cout << co; return 0; } co++; if (co % 3 == 1) { a = b + c - 1; } else if (co % 3 == 2) { b = a + c - 1; } else c = a + b - 1; } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; class TaskC { public: void solve(std::istream& in, std::ostream& out) { int x, y; in >> x >> y; if (x == y) out << 0; else { int res = 0; int arr[3] = {y, y, y}; while (arr[0] != x or arr[1] != x or arr[2] != x) { sort(arr, arr + 3); swap(arr[0], arr[2]); for (int i = x; i > y; --i) { if (i + arr[0] > arr[1] and i + arr[1] > arr[0] and arr[0] + arr[1] > i) { arr[2] = i; break; } } res++; } out << res; } } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); TaskC solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y, a, b, c; scanf("%d %d", &x, &y); a = b = c = y; int cnt = 0; while (1) { cnt++; if (a >= x && b >= x && c >= x) { printf("%d\n", cnt - 1); return 0; } else if (cnt % 3 == 1) a = b + c - 1; else if (cnt % 3 == 2) b = a + c - 1; else c = a + b - 1; } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> const double PI = acos(-1.0); const double e = exp(1.0); const int INF = 0x7fffffff; ; template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> inline T Min(T a, T b) { return a < b ? a : b; } template <class T> inline T Max(T a, T b) { return a > b ? a : b; } bool cmpbig(int a, int b) { return a > b; } bool cmpsmall(int a, int b) { return a < b; } using namespace std; char dir[100010]; int main() { int x, y; while (~scanf("%d%d", &x, &y)) { int cnt = 0; int a = y, b = y, c = y; while (a != x || b != x || c != x) { if (a <= b && a <= c) { if (b + c - 1 < x) a = b + c - 1; else a = x; cnt++; } else if (b <= a && b <= c) { if (a + c - 1 < x) b = a + c - 1; else b = x; cnt++; } else if (c <= a && c <= b) { if (a + b - 1 < x) c = a + b - 1; else c = x; cnt++; } } printf("%d\n", cnt); } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, s[3], ans = 0; cin >> a >> b; for (int i = 0; i < 3; i++) s[i] = b; while (s[0] != a || s[1] != a || s[2] != a) { if (s[2] < a) { s[2] = s[0] + s[1] - 1; if (s[2] > a) s[2] = a; ans++; } if (s[1] < a) { s[1] = s[0] + s[2] - 1; if (s[1] > a) s[1] = a; ans++; } if (s[0] < a) { s[0] = s[1] + s[2] - 1; if (s[0] > a) s[0] = a; ans++; } } cout << ans << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int a = y, b = y, c = y; int count = 0; while (1) { if (a >= x && b >= x && c >= x) { break; } count++; if (count % 3 == 1) { a = b + c - 1; } if (count % 3 == 2) { b = a + c - 1; } if (count % 3 == 0) { c = a + b - 1; } } cout << count << endl; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y = map(int,raw_input().split()) ans = 0 p = [y,y,y] while True: if all(t == x for t in p): break p.sort() ans +=1 m = max(p[1]+p[2]-1,1) if m >= x: p[0] = x else: p[0] = m print ans
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; cin >> x >> y; long long int result(0); long long int y1(y), y2(y), y3(y); long long int i = 1; while (y1 < x or y2 < x or y3 < x) { if (i == 1) { if (y2 + y3 - 1 > x) { y1 = x; } else { y1 = y2 + y3 - 1; } i++; result++; } else if (i == 2) { if (y1 + y3 - 1 > x) { y2 = x; } else { y2 = y1 + y3 - 1; } i++; result++; } else { result++; if (y1 + y2 - 1 > x) { y3 = x; } else { y3 = y1 + y2 - 1; } i = 1; } } cout << result; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.Scanner; public class C { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan=new Scanner(System.in); int x=scan.nextInt(); int y=scan.nextInt(); int a=y,b=y,c=y; int cnt=0; while(a!=x||b!=x||c!=x){ c=a+b-1<x?a+b-1:x; int temp=c; c=b;b=a;a=temp; cnt++; } System.out.println(cnt); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; const long long inf = LLONG_MAX / 1000; int a[200100]; int i, n, m; int counter = 0; bool ok(int a, int b, int c) { if (a < b + c && b < a + c && c < a + b && max(a, max(b, c)) <= n) return true; return false; } int main() { cin >> n >> m; for (i = 1; i <= 3; i++) a[i] = m; while (true) { while (ok(a[1] + 1, a[2], a[3])) { a[1]++; } counter++; sort(a + 1, a + 3 + 1); if (a[1] == n && a[2] == n && a[3] == n) { cout << counter; return 0; } } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.lang.*; public class Third{ static long mod=1000000007; public static void main(String[] args) throws Exception{ InputReader in = new InputReader(System.in); PrintWriter pw=new PrintWriter(System.out); //int t=in.readInt(); //while(t-->0) //{ int x=in.readInt(); int y=in.readInt(); int a=y; int b=y; int c=y; int ans=0; while(a!=x||b!=x||c!=x) { ans++; if(a<=b&&a<=c) { int max=b+c-1; a=max; if(a>x) a=x; } else if(b<=a&&b<=c) { int max=a+c-1; b=max; if(b>x) b=x; } else { int max=a+b-1; c=max; if(c>x) c=x; } } pw.println(ans); //} pw.close(); } public static long gcd(long x,long y) { if(x%y==0) return y; else return gcd(y,x%y); } public static int gcd(int x,int y) { if(x%y==0) return y; else return gcd(y,x%y); } public static int abs(int a,int b) { return (int)Math.abs(a-b); } public static long abs(long a,long b) { return (long)Math.abs(a-b); } public static int max(int a,int b) { if(a>b) return a; else return b; } public static int min(int a,int b) { if(a>b) return b; else return a; } public static long max(long a,long b) { if(a>b) return a; else return b; } public static long min(long a,long b) { if(a>b) return b; else return a; } public static long pow(long n,long p,long m) { long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; if(result>=m) result%=m; p >>=1; n*=n; if(n>=m) n%=m; } return result; } public static long pow(long n,long p) { long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; p >>=1; n*=n; } return result; } static class Pair implements Comparable<Pair> { int a,b; Pair (int a,int b) { this.a=a; this.b=b; } public int compareTo(Pair o) { // TODO Auto-generated method stub if(this.a!=o.a) return Integer.compare(this.a,o.a); else return Integer.compare(this.b, o.b); //return 0; } public boolean equals(Object o) { if (o instanceof Pair) { Pair p = (Pair)o; return p.a == a && p.b == b; } return false; } public int hashCode() { return new Integer(a).hashCode() * 31 + new Integer(b).hashCode(); } } static long sort(int a[]) { int n=a.length; int b[]=new int[n]; return mergeSort(a,b,0,n-1);} static long mergeSort(int a[],int b[],long left,long right) { long c=0;if(left<right) { long mid=left+(right-left)/2; c= mergeSort(a,b,left,mid); c+=mergeSort(a,b,mid+1,right); c+=merge(a,b,left,mid+1,right); } return c; } static long merge(int a[],int b[],long left,long mid,long right) {long c=0;int i=(int)left;int j=(int)mid; int k=(int)left; while(i<=(int)mid-1&&j<=(int)right) { if(a[i]<=a[j]) {b[k++]=a[i++]; } else { b[k++]=a[j++];c+=mid-i;}} while (i <= (int)mid - 1) b[k++] = a[i++]; while (j <= (int)right) b[k++] = a[j++]; for (i=(int)left; i <= (int)right; i++) a[i] = b[i]; return c; } public static int[] radixSort(int[] f) { int[] to = new int[f.length]; { int[] b = new int[65537]; for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++; for(int i = 1;i <= 65536;i++)b[i]+=b[i-1]; for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i]; int[] d = f; f = to;to = d; } { int[] b = new int[65537]; for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++; for(int i = 1;i <= 65536;i++)b[i]+=b[i-1]; for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i]; int[] d = f; f = to;to = d; } return f; } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } //BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); //StringBuilder sb=new StringBuilder(""); //InputReader in = new InputReader(System.in); //PrintWriter pw=new PrintWriter(System.out); //String line=br.readLine().trim(); //int t=Integer.parseInt(br.readLine()); // while(t-->0) //{ //int n=Integer.parseInt(br.readLine()); //long n=Long.parseLong(br.readLine()); //String l[]=br.readLine().split(" "); //int m=Integer.parseInt(l[0]); //int k=Integer.parseInt(l[1]); //String l[]=br.readLine().split(" "); //l=br.readLine().split(" "); /*int a[]=new int[n]; for(int i=0;i<n;i++) { a[i]=Integer.parseInt(l[i]); }*/ //System.out.println(" "); //} }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import sys,os,io from sys import stdin from functools import cmp_to_key from bisect import bisect_left , bisect_right from collections import defaultdict def ii(): return int(input()) def li(): return list(map(int,input().split())) if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w") # else: # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def fun(a,x): if min(a)>=x: return 1 return 0 for _ in range(1): x,y = li() a=[y,y,y] f = 0 cnt=0 while(fun(a,x)==0): if f==0: # y+a,y,y # y+a<y+y sum2 = a[1]+a[2]-a[0] a[0]+=sum2-1 elif f==1: sum2 = a[0]+a[2]-a[1] a[1]+=sum2-1 else: sum2 = a[1]+a[0]-a[2] a[2]+=sum2-1 f+=1 f%=3 cnt+=1 print(cnt)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class Solution3 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int i,x = sc.nextInt(), y = sc.nextInt(); int arr[] = new int[]{y,y,y}; for(i = 0;arr[0]<x||arr[1]<x||arr[2]<x;i++){ arr[i%3] = arr[(i+1)%3]+arr[(i+2)%3]-1; } System.out.println(i); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long x, y, c = 0, i = 0; cin >> x >> y; long long arr[3]; for (i = 0; i < 3; i++) arr[i] = y; while (true) { if (arr[0] == x && arr[1] == x && arr[2] == x) { cout << c; return 0; } c++; sort(arr, arr + 3); long long max = arr[1] + arr[2]; if (x >= max) arr[0] = max - 1; else arr[0] = x; } }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { ifstream fin("input.txt"); int i, j; int ans = 0, a, b, c, x, y; cin >> x >> y; a = y; b = y; c = y; while (true) { if (a < b) { if (a < c) { a = (b + c) - 1; ans++; if (a >= x) { ans += 2; break; } } else { c = (a + c) - 1; ans++; if (c >= x) { ans += 2; break; } } } else { if (b < c) { b = (a + c) - 1; ans++; if (b >= x) { ans += 2; break; } } else { c = (b + a) - 1; ans++; if (c >= x) { ans += 2; break; } } } } cout << ans << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return n & two(b); } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } int x, y; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> x >> y; int a = y, b = y, c = y; int ans = 0; while (1) { if (a >= x and b >= x and c >= x) { cout << ans << endl; break; } ans++; if (ans % 3 == 1) { b = a + c - 1; } if (ans % 3 == 2) { a = b + c - 1; } if (ans % 3 == 0) { c = a + b - 1; } } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
//package c370; import java.util.Arrays; import java.util.Scanner; public class q3 { public static void main(String args[]) { Scanner s=new Scanner(System.in); int x=s.nextInt(); int y=s.nextInt(); int a=y,b=y,c=y; int co=0; while(!(a==x && b==x && c==x)) { // System.out.println(a+" "+b+" "+c); int min[] = get(a,b,c); int max=min[2]+min[1]; a=Math.min(x, max-1); b=min[1]; c=min[2]; co++; } System.out.println(co); } public static int[] get(int ... a) { Arrays.sort(a); return a; } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Sanket Makani */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader sc, PrintWriter w) { int a = sc.nextInt(); int b = sc.nextInt(); int arr[] = new int[3]; int count = 0; Arrays.fill(arr, b); while (true) { Arrays.sort(arr); if ((arr[0] + arr[1] + arr[2]) / 3 == a) break; arr[0] = Math.min(arr[1] + arr[2] - 1, a); count++; } w.println(count); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x, y = map(int, input().split()) a = b = c = y ans = 0 while min(a, b, c) != x: arr = list(sorted([a, b, c])) arr[0] = min(x, arr[1] + arr[2] - 1) a, b, c = arr ans += 1 print(ans)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const long double PI = 3.14159265358979323846; struct myCompare { bool operator()(const std::pair<int, int> &l, const std::pair<int, int> &r) const { return l.first < r.first; } }; const int MAXN = 1e5 + 3; int x, y; void solve() { cin >> x >> y; int a, b, c; a = b = c = y; int ma, res = 0, t; if (x != y) { while (a != x || b != x || c != x) { res++; if (a < b) swap(a, b); if (a < c) swap(a, c); if (b < c) swap(b, c); c = min(x, a + b - 1); } } cout << res; } int main() { solve(); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int ara[5]; int main() { int x, y, z, cnt, res; while (cin >> x >> res) { cnt = 0; ara[1] = res; ara[2] = res; ara[3] = res; while (ara[1] < x) { cnt++; ara[1] = ara[2] + ara[3] - 1; sort(ara + 1, ara + 4); } cout << cnt << endl; } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
[x, y] = [int(x) for x in input().split()] a, b, c = y, y, y res = 0 while a != x or b != x or c != x: res += 1 minimum = min(a, b, c) if a == minimum: a = min(b+c-1, x) elif b == minimum: b = min(a+c-1, x) else: c = min(a+b-1, x) print(res)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int DDDF = 0, DDDS = 0; bool Sortpair(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } string con(string s, int i) { string t = ""; for (int k = 0; k < i; k++) t += s[k]; for (int j = (i + 1); j < s.length(); j++) { t += s[j]; } return t; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int x, y; cin >> x >> y; vector<int> v(3, y); int r = 0; while (v[0] != x) { v[0] = min(v[1] + v[2] - 1, x); sort(v.begin(), v.end()); r++; } cout << r; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; import java.io.*; public class CodeForces { public static void main(String[] args) throws IOException { Reader.init(System.in) ; PrintWriter writer = new PrintWriter(System.out); int x = Reader.nextInt(); int y = Reader.nextInt(); int arr[] = {y,y,y}; int cnt = 0; while(arr[0] < x || arr[1] < x || arr[2] < x){ arr[0] = arr[1] + arr[2] - 1; Arrays.sort(arr); cnt++; } writer.println(cnt); writer.close(); } } class Edge implements Comparable<Edge>{ int to; int from; int cost; Edge(int a, int b, int c){ from = a; to = b; cost = c; } @Override public int compareTo(Edge t) { return t.cost - cost; } } class Pair { int sum, mod, num; public Pair(int sum, int mod, int num) { this.sum = sum; this.mod = mod; this.num = num; } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; public static int pars(String x) { int num = 0; int i = 0; if (x.charAt(0) == '-') { i = 1; } for (; i < x.length(); i++) { num = num * 10 + (x.charAt(i) - '0'); } if (x.charAt(0) == '-') { return -num; } return num; } static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } static void init(FileReader input) { reader = new BufferedReader(input); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer( reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return pars(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long x, z, a, b, c, i = 1, y = 0; cin >> x >> z; a = b = c = z; while (1) { if (i % 3 == 1 && a < x) { if (c + b < x) { a = c + b - 1; } else if (c + b == x) a = x - 1; else a = x; i++; y++; } if (i % 3 == 2 && b < x) { if (a + c < x) { b = a + c - 1; } else if (c + a == x) b = x - 1; else b = x; i++; y++; } if (i % 3 == 0 && c < x) { if (a + b < x) { c = a + b - 1; } else if (a + b == x) c = x - 1; else c = x; i++; y++; } if (a >= x && b >= x && c >= x) break; } cout << y; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; public class CF712C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); int a = y, b = y, c = y, cnt = 0; while (a < x) { int d = Math.min(x, b + c - 1); a = b; b = c; c = d; cnt++; } System.out.println(cnt); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf("%d%d", &x, &y); int res = 0; int a, b, c; a = b = c = y; while (b + c < x) { a = b; b = c; c = a + b - 1; res++; } if (b + c == x) res += 4; else if (b + c > x) res += 3; printf("%d\n", res); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class MemoryAndDeEvolution { static int x,y; public static void main(String[] args) throws NumberFormatException, IOException { Scanner sc = new Scanner(System.in); x = sc.nextInt(); y = sc.nextInt(); int[] arr = new int[3]; arr[0] = arr[1] = arr[2] = y; int sol = 0; while(true) { if(arr[0]>=x && arr[1]>=x && arr[2]>=x) break; Arrays.sort(arr); arr[0] = arr[1]+arr[2]-1; sol++; } System.out.println(sol); } static class Scanner { BufferedReader br; StringTokenizer st; Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } String next() throws IOException { while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } String nextLine() throws IOException { return br.readLine(); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int a, b, ans = 0; bool flag; void dfs(int x, int y, int z) { if (x == z && x == b) return; int t[3]; t[0] = x, t[1] = y, t[2] = z; if (t[0] + t[1] - 1 >= b) t[2] = b; else t[2] = t[0] + t[1] - 1; ++ans; sort(t, t + 3); dfs(t[2], t[1], t[0]); } int main() { scanf("%d%d", &a, &b); if (a < b) flag = true; else flag = false; if (!flag) swap(a, b); dfs(a, a, a); printf("%d\n", ans); return 0; }
CPP