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
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int ans = 0; int B[3]; B[0] = y; B[1] = y; B[2] = y; while (!(B[0] == x && B[1] == x && B[2] == x)) { if (ans % 3 == 0) { B[0] = min(x, B[1] + B[2] - 1); } else if (ans % 3 == 1) { B[1] = min(x, B[0] + B[2] - 1); } else { B[2] = min(x, B[0] + B[1] - 1); } 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
import java.util.*; import java.io.*; public class C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(); int y = scan.nextInt(); int[] a = new int[55]; a[1] = 1;a[2] = 2; for(int i = 3;i<=54;i++){ a[i] = a[i-1]+a[i-2]; } int k = 0; for(int i = 1;i<=25;i++){ if(a[i]*y-(a[i]-1)>=x){ k = i; break; } } if(x==y) System.out.println(0); else System.out.println(k+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
/** * Created by naeem on 9/24/16. */ import java.util.*; import java.io.*; public class C { public static void main(String[] args) throws IOException { // Scanner file = new Scanner(new File("c.txt")); Scanner file = new Scanner(System.in); String[] parts = file.nextLine().split(" "); int x = Integer.parseInt(parts[0]); int y = Integer.parseInt(parts[1]); int[] sizes = {y, y, y}; int total = 0; while(min(sizes) != x) { total++; int sum = sizes[0] + sizes[1] + sizes[2]; sizes[minIndex(sizes)] = Math.min(x, sum - sizes[minIndex(sizes)] - 1); // System.out.println(sizes[0] + " " + sizes[1] + " " + sizes[2]); } System.out.println(total); } public static int minIndex(int[] sz) { if(sz[2] <= sz[1] && sz[2] <= sz[0]) return 2; if(sz[1] <= sz[2] && sz[1] <= sz[0]) return 1; return 0; } public static int min(int[] sz) { return Math.min(sz[0], Math.min(sz[1], sz[2])); } }
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()) a = [y, y, y] tot = 0 got = 0 while True: for i in xrange(3): a[i] = a[(i + 1)%3] + a[(i + 2)%3] - 1 #print a[i], a[(i+1)%3], a[(i+2)%3] if a[i] > x: a[i] = x tot += 1 if (a[0] == a[1] and a[1] == a[2] and a[2] == x): got = 1 break if got == 1: break print tot
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
import java.util.*; import java.io.*; import java.math.*; public class C{ static int x,y,res; static int raise(int a[],int g){ int rs=0; while(true){ Arrays.sort(a); if (a[0]>=g) break; rs++; a[0]=Math.min(g,a[1]+a[2]-1); } return rs; } static void MainMethod()throws Exception{ x=reader.nextInt(); y=reader.nextInt(); if (x>y){ int t=x; x=y; y=t; } int a[]=new int [3]; a[0]=x; a[1]=x; a[2]=x; res=raise(a, y); printer.println(res); } public static void main(String[] args)throws Exception{ MainMethod(); printer.close(); } static void halt(){ printer.close(); System.exit(0); } static PrintWriter printer=new PrintWriter(new OutputStreamWriter(System.out)); static class reader{ static BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer token=new StringTokenizer(""); static String readNextLine() throws Exception{ return bReader.readLine(); } static String next() throws Exception{ while (token.hasMoreTokens()==false){ token=new StringTokenizer(bReader.readLine()); } return token.nextToken(); } static int nextInt()throws Exception{ while (token.hasMoreTokens()==false){ token=new StringTokenizer(bReader.readLine()); } return Integer.parseInt(token.nextToken()); } static long nextLong()throws Exception{ while (token.hasMoreTokens()==false){ token=new StringTokenizer(bReader.readLine()); } return Long.parseLong(token.nextToken()); } static double nextDouble()throws Exception{ while (token.hasMoreTokens()==false){ token=new StringTokenizer(bReader.readLine()); } return Double.parseDouble(token.nextToken()); } } static class MyMathCompute{ static long [][] MatrixMultiplyMatrix(long [][] A, long [][] B, long mod) throws Exception{ int n=A.length, m=B[0].length; int p=A[0].length; int i,j,k; if (B.length!=p) throw new Exception("invalid matrix input"); long [][] res=new long [n][m]; for (i=0;i<n;i++) for (j=0;j<m;j++){ if (A[i].length!=p) throw new Exception("invalid matrix input"); res[i][j]=0; for (k=0;k<p;k++) res[i][j]=(res[i][j]+((A[i][k]*B[k][j])% mod))% mod; } return res; } static double [][] MatrixMultiplyMatrix(double [][] A, double [][] B ) throws Exception{ int n=A.length, m=B[0].length; int p=A[0].length; int i,j,k; if (B.length!=p) throw new Exception("invalid matrix input"); double [][] res=new double [n][m]; for (i=0;i<n;i++) for (j=0;j<m;j++){ if (A[i].length!=p) throw new Exception("invalid matrix input"); res[i][j]=0; for (k=0;k<p;k++) res[i][j]=res[i][j]+(A[i][k]*B[k][j]); } return res; } static long [][] MatrixPow(long [][] A,long n, long mod) throws Exception{ if (n==1) return A; long [][] res=MatrixPow(A, n/2, mod); res=MatrixMultiplyMatrix(res, res, mod); if ((n % 2) == 1) res=MatrixMultiplyMatrix(A,res, mod); return res; } static double [][] MatrixPow(double [][] A,long n) throws Exception{ if (n==1) return A; double[][] res=MatrixPow(A, n/2); res=MatrixMultiplyMatrix(res, res); if ((n % 2) == 1) res=MatrixMultiplyMatrix(A,res); return res; } static long pow(long a,long n,long mod){ a= a % mod; if (n==0) return 1; long k=pow(a,n/2,mod); if ((n % 2)==0) return ((k*k)%mod); else return (((k*k) % mod)*a) % mod; } static double pow(double a,long n){ if (n==0) return 1; double k=pow(a,n/2); if ((n % 2)==0) return (k*k); else return (((k*k) )*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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Codeforces{ public static void main(String[] args) throws IOException{ Scan scan = new Scan(); int m = scan.nextInt(); int a = scan.nextInt(), b = a, c = a; int counter = 0; while(a < m || b < m || c < m){ counter++; if(a <= b && a <= c) while(a < m && triangle(a + 1, b, c)) a++; else if(b <= a && b <= c) while(b < m && triangle(a, b + 1, c)) b++; else while(c < m && triangle(a, b, c + 1)) c++; } System.out.println(counter); } public static boolean triangle(int a, int b, int c){ return (b > Math.abs(a - c)) && (b < Math.abs(a + c)); } public static class Scan{ BufferedReader br; String[] s; String str; int strIndex; int index; public Scan(){ br = new BufferedReader(new InputStreamReader(System.in)); index = 0; s = new String[0]; str = "a"; strIndex = 1; } public String nextLine() throws IOException{ return br.readLine(); } public char nextChar() throws IOException{ if(strIndex == str.length()){ str = br.readLine(); strIndex = 0; } strIndex++; return str.charAt(strIndex - 1); } public char[] nextCharArray() throws IOException{ str = br.readLine(); return str.toCharArray(); } public int[] nextIntArray() throws IOException{ s = br.readLine().split(" "); int[] result = new int[s.length]; for(int i = 0; i < s.length; i++) result[i] = Integer.parseInt(s[i]); return result; } public long[] nextLongArray() throws IOException{ s = br.readLine().split(" "); long[] result = new long[s.length]; for(int i = 0; i < s.length; i++) result[i] = Long.parseLong(s[i]); return result; } public double[] nextDoubleArray() throws IOException{ s = br.readLine().split(" "); double[] result = new double[s.length]; for(int i = 0; i < s.length; i++) result[i] = Double.parseDouble(s[i]); return result; } public int nextInt() throws IOException{ if(index == s.length){ s = br.readLine().split(" "); index = 0; } index++; return Integer.parseInt(s[index - 1]); } public long nextLong() throws IOException{ if(index == s.length){ s = br.readLine().split(" "); index = 0; } index++; return Long.parseLong(s[index - 1]); } public double nextDouble() throws IOException{ if(index == s.length){ s = br.readLine().split(" "); index = 0; } index++; return Double.parseDouble(s[index - 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.PriorityQueue; import java.util.StringTokenizer; public class C { public static boolean valid(int a, int b , int c){ return a+b>c && a+c>b && b+c>a; } static int a, b , c; public static int bi ( int lo ,int hi, int a, int b){ int res = 0; while(lo<=hi){ int mid = (lo+hi )/2; if(valid(mid, b, a)){ res = mid; hi = mid-1; // res=hi; } else lo = mid+1; // hi--; } return res; } public static void main(String[] args)throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); a=b=c=sc.nextInt(); int cnt = 0; PriorityQueue<Integer> pq = new PriorityQueue<>(); pq.add(a); pq.add(b); pq.add(c); while(true){ if(a==b && b==c && a==t) break; a = pq.remove(); b = pq.remove(); c = pq.remove(); a = b+c>t? t:b+c-1; cnt++; pq.add(a); pq.add(b); pq.add(c); if(a==b && b==c && a==t) break; // System.out.println(a+" "+b+" "+c); } System.out.println(cnt); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
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
a,b=input().strip().split(' ') a,b=(int(a),int(b)) l=[b,b,b] ans=0 while l!=[a,a,a]: l.sort() #print(l) l[0]=min(l[1]+l[2]-1,a) 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
L=map(int, raw_input().split()) def maxInc(temp, x, res): if [x]==list(set(temp)): return res else: a=max(temp) c=min(temp) b=sum(temp)-a-c c=min(a+b-1, x) return maxInc([a, b, c], x, res+1) x=max(L) y=min(L) temp=[y, y, y] print maxInc(temp, x, 0)
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> const int N = 1e5 + 1; using namespace std; long long x, y; long long a, b, c; int main() { std ::ios ::sync_with_stdio(false); cin >> x >> y; long long ans = 0; a = b = c = y; while (a != x || b != x || c != x) { ans++; if (a > b) swap(a, b); if (b > c) swap(b, c); if (a > b) swap(a, b); a = min(b + c - 1, x); } 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
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int x, y; cin >> x >> y; vector<int> len = {y, y, y}; int ans = 0; while (len[0] < x || len[1] < x || len[2] < x) { if (ans % 3 == 0) { len[0] = len[1] + len[2] - 1; } if (ans % 3 == 1) { len[1] = len[0] + len[2] - 1; } if (ans % 3 == 2) { len[2] = len[0] + len[1] - 1; } ans++; } cout << ans << '\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 Template implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Exception e) { String filename = ""; if (filename.isEmpty()) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader(filename + ".in")); out = new PrintWriter(filename + ".out"); } } } String readString() throws IOException { while (!tok.hasMoreTokens()) { try { tok = new StringTokenizer(in.readLine(), " :"); } catch (Exception e) { return null; } } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } int[] readIntArray(int size) throws IOException { int[] res = new int[size]; for (int i = 0; i < size; i++) { res[i] = readInt(); } return res; } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } <T> List<T>[] createGraphList(int size) { List<T>[] list = new List[size]; for (int i = 0; i < size; i++) { list[i] = new ArrayList<>(); } return list; } public static void main(String[] args) { new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start(); } long timeBegin, timeEnd; void time() { timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } long memoryTotal, memoryFree; void memory() { memoryFree = Runtime.getRuntime().freeMemory(); System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB"); } public void run() { try { timeBegin = System.currentTimeMillis(); memoryTotal = Runtime.getRuntime().freeMemory(); init(); solve(); out.close(); if (System.getProperty("ONLINE_JUDGE") == null) { time(); memory(); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } void solve() throws IOException { int x = readInt(); int y = readInt(); int[] a = {y, y, y}; int ans = 0; while (true) { Arrays.sort(a); if (a[0] == x) break; a[0] = Math.min(x, a[1] + a[2] - 1); ans++; } out.println(ans); // int[] a = {x, x, x}; // int ans = 0; // while (true) { // Arrays.sort(a); // if (a[2] == y) break; // a[2] = Math.max(y, a[1] - a[0] + 1); // ans++; // } // out.println(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
s = raw_input() x = int(s.split()[0]) y = int(s.split()[1]) t = [y for i in range(3)] n = 0 while True: t = sorted(t) if t[0] == x: break t[0] = t[1] + t[2] - 1 n += 1 if t[0] > x: t[0] = x print n
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
import java.io.*; import java.util.*; import java.text.DecimalFormat; public class Dfs { public static void main(String[] args)throws Exception { reader in = new reader(System.in); int a=in.nextInt(); int m=in.nextInt(); int x =m;int y=m;int z=m; int count =0; while(x!=a||y!=a||z!=a){ // System.out.println(x+" "+y+" "+z); if(x<=y&&x<=z){ if(x!=a){ x=(z+y-1); if(x>a) x=a; count++; } } else if(y<=x&&y<=z){ if(y!=a){ y=x+z-1; if(y>a) y=a; count++; } } else { if(z!=a){ z=x+y-1; if(z>a) z=a; count++; } } } System.out.println(count); } static class reader{ BufferedReader read ; StringTokenizer tok; public reader(InputStream stream){ read= new BufferedReader(new InputStreamReader(stream)); tok=null; } String next()throws Exception{ while(tok==null||!tok.hasMoreElements()){ tok= new StringTokenizer(read.readLine()); } return tok.nextToken(); } int nextInt()throws Exception{ 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.StringTokenizer; public class Solution123{ static int coun = 0; static int size = 0; public static void main(String[] args) throws IOException{ FastReader sc = new FastReader(); int a = sc.nextInt(); int b = sc.nextInt(); int[] arr = new int[3]; arr[0] = b; arr[1] = b; arr[2] = b; int count = 0; while(arr[0] < a || arr[1] < a || arr[2] < a){ arr[count%3] = arr[(count + 1)%3] + arr[(count + 2)%3] - 1; count++; } System.out.println(count); } public static int complement(int index){ if(index == 0){ return 1; } return 0; } private static long gcd(long a, long b) { while (b > 0) { long temp = b; b = a % b; // % is remainder a = temp; } return a; } void convertDegree(){ } private static long gcd(long[] input) { long result = input[0]; for(int i = 1; i < input.length; i++) result = gcd(result, input[i]); return result; } private static long lcm(long a, long b) { return a * (b / gcd(a, b)); } private static long lcm(long[] input) { long result = input[0]; for(int i = 1; i < input.length; i++) result = lcm(result, input[i]); return result; } public static boolean[] sieveAlgo(int n){ boolean isPrime[] = new boolean[n + 1]; for (int i = 2; i <= n; i++) { isPrime[i] = true; } // mark non-primes <= n using Sieve of Eratosthenes for (int factor = 2; factor*factor <= n; factor++) { // if factor is prime, then mark multiples of factor as nonprime // suffices to consider mutiples factor, factor+1, ..., n/factor if (isPrime[factor]) { for (int j = factor; factor*j <= n; j++) { isPrime[factor*j] = false; } } } return isPrime; } public static int binarySearch(int[] arr,int low,int high,int key){ while(low <= high){ int mid = (low + high)/2; if(arr[mid] == key){ return mid; }else if(arr[mid] < key){ low = mid + 1; }else{ high = mid - 1; } } return -1; } public static int ternarySearch(int[] arr,int l,int r,int key){ if(r >= l){ int mid1 = l + (r-1)/3; int mid2 = r - (r-1)/3; if(arr[mid1] == key){ return mid1; }else if(arr[mid2] == key){ return mid2; } if(key < arr[mid1]){ return ternarySearch(arr,l,mid1-1,key); }else if(key > arr[mid2]){ return ternarySearch(arr,mid2 + 1,r,key); }else{ return ternarySearch(arr,mid1 + 1,mid2 - 1,key); } } return -1; } public static double fun(double x){ return 2 * x * x - 12 * x + 7; } public static double tsModified(double start,double end){ double l = start; double r = end; for(int i = 0;i < 200;i++){ double mid1 = (l * 2 + r)/3; double mid2 = (l + 2 * r)/3; if(fun(mid1) < fun(mid2)){ r = mid2; }else{ l = mid1; } } double x = l; return fun(x); } public static String fmt(double d) { if(d == (long) d) return String.format("%d",(long)d); else return String.format("%s",d); } public static int[][] comparator(int[][] arr){ Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] a,int[] b) { Integer a1 = a[1]; Integer b1 = b[1]; return b1.compareTo(a1); } }); return arr; } public static StringBuilder[][] comparator2(StringBuilder[][] arr){ Arrays.sort(arr, new Comparator<StringBuilder[]>() { @Override public int compare(StringBuilder[] a,StringBuilder[] b) { StringBuilder a1 = a[0]; StringBuilder b1 = b[0]; return a1.toString().compareTo(b1.toString()); } }); return arr; } public static int[][] comparator2(int[][] arr){ Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] a,int[] b) { Integer a1 = a[0]; Integer b1 = b[0]; return b1.compareTo(a1); } }); return arr; } 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 String min(int m,int n){ int[] arr = new int[m]; arr[0] = 1; int sum = 1; int j = m - 1; for(int i = 1;i <= 18* m + 10;i++){ if(sum != n){ if(arr[j] == 9){ j--; }else{ arr[j]++; sum++; } } else{ break; } } StringBuilder min = new StringBuilder(""); for(int i = 0;i < arr.length;i++){ min.append(arr[i]); } return min.toString(); } public static String max(int m,int n){ int[] arr = new int[m]; arr[0] = 1; int sum = 1; int j = 0; for(int i = 1;i <= 9 * m + 10;i++){ if(sum != n){ if(arr[j] == 9){ j++; }else{ arr[j]++; sum++; } } else{ break; } } StringBuilder min = new StringBuilder(""); for(int i = 0;i < arr.length;i++){ min.append(arr[i]); } return min.toString(); } public static int KMPSearch(String txt,String pat){ int m = pat.length(); int n = txt.length(); int lps[] = new int[m]; int j = 0; int count = 0; PrefixTable(pat,m,lps); int i = 0; while (i < n) { if (pat.charAt(j) == txt.charAt(i)) { j++; i++; } if (j == m) { count++; j = lps[j-1]; } else if (i < n && pat.charAt(j) != txt.charAt(i)) { if (j != 0) j = lps[j-1]; else i = i+1; } } return count; } public static void PrefixTable(String pat,int m,int[] lps){ int len = 0; int i = 1; lps[0] = 0; while(i < m){ if(pat.charAt(i) == pat.charAt(len)){ lps[i] = len + 1; i++; len++; }else if(len > 0){ len = lps[len - 1]; }else{ lps[i] = 0; i++; } } } public int digit(int x){ int temp = x; int count = 0; while(temp != 0){ count++; temp = temp/10; } return count; } public int sum(int x){ int temp = x; int count = 0; while(temp != 0){ count += temp % 10; temp = temp/10; } return count; } public int product(int x){ int temp = x; int count = 1; while(temp != 0){ count*=temp % 10; temp = temp/10; } return count; } public boolean isValid2(int x){ int temp = x; while(temp != 0){ if(temp % 10 == 0){ return false; } temp = temp/10; } return true; } public boolean isValid(int x){ if(!isValid2(x)){ return false; }else{ if(product(x) <= sum(x)){ return true; } return false; } } }
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 maxn = 200005; const long long MOD = 1e9 + 7; void solve() { long long x, y; cin >> x >> y; long long a[3]; a[0] = a[1] = a[2] = y; long long tm = 0; while (1) { a[0] = min(x, a[1] + a[2] - 1); tm++; sort(a, a + 3); if (a[0] == x) { break; } } cout << tm; } int32_t main() { long long 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.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,b,c; a=b=c=y; boolean a_flag,b_flag,c_flag; a_flag=b_flag=c_flag=true; int ans=0; while( a_flag || b_flag || c_flag) { if(a_flag && b+c>x) { a=x; a_flag=false; ans++; } else if(a_flag) { a=b+c-1; ans++; } if(b_flag && a+c>x) { b=x; b_flag=false; ans++; } else if(b_flag) { b=a+c-1; ans++; } if(c_flag && a+b>x) { c=x; c_flag=false; ans++; } else if(c_flag) { c=a+b-1; ans++; } } System.out.println(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
import java.util.Scanner; /* ========== ========== ========== */ // Author - Vamsi Sangam // /* ========== ========== ========== */ public class MemoryAndDeevolution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int x = s.nextInt(); int y = s.nextInt(); int turns = 0; int a = y, b = y, c = y; while (a != x || b != x || c != x) { if (a <= b && a <= c && a != x) { a = (int) Math.min(b + c - 1, x); } else if (b <= a && b <= c && b != x) { b = (int) Math.min(a + c - 1, x); } else if (c <= a && c <= b && c != x) { c = (int) Math.min(a + b - 1, x); } ++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
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int a, b, c; int pos; int cot = 0; cin >> n >> m; a = m, b = m, c = m; while (a != n || b != n || c != n) { if (a != n) { int pos1; for (int i = 1; i <= n; i++) { if ((a + i) + b > c && (b + c) > (a + i) && (a + i) + c > b && (a + i) <= n) { pos1 = i; } } a = a + pos1; cot++; } if (b != n) { int pos2; for (int i = 1; i <= n; i++) { if ((b + i) + a > c && (a + c) > (b + i) && (b + i) + c > a && (b + i) <= n) { pos2 = i; } } b = b + pos2; cot++; } if (c != n) { int pos3; for (int i = 1; i <= n; i++) { if ((c + i) + a > b && b + (c + i) > a && b + a > c + i && (c + i) <= n) { pos3 = i; } } c = pos3 + c; cot++; } } cout << cot << 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 ra() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int e, s, x, y, z, ans; int main() { e = ra(); s = ra(); int x, y, z; x = y = z = s; for (;;) { ans++; x = y + z - 1; int t = z, r = y; z = x; y = t; x = y; if (z >= e) break; } cout << ans + 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; const int TAM = 300000 + 50; const long long MOD = 1000000007LL; int x, y; int main() { scanf("%d%d", &x, &y); vector<int> v(3, y); int i = 0; int r = 0; while (v[0] != x || v[1] != x || v[2] != x) { switch (i) { case 0: v[0] = min(x, v[1] + v[2] - 1); break; case 1: v[1] = min(x, v[0] + v[2] - 1); break; case 2: v[2] = min(x, v[1] + v[0] - 1); break; } r++; i = (i + 1) % 3; } cout << r << 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
mystring = raw_input() x, y = (map(str.strip, mystring.split(' '))) #print x, y x, y = [int(x), int(y)] a, b, c = y, y, y turns = 0 while True: if a >= x and b >= x and c >= x: print turns break turns += 1 if turns%3 == 1: a = b+c-1 if turns%3 == 2: b = a+c-1 if turns%3 == 0: c = a+b-1
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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.StringTokenizer; public class C { //IO static BufferedReader f; static PrintWriter out; static StringTokenizer st; final public static void main( String[] args ) throws IOException { f = new BufferedReader( new InputStreamReader( System.in ) ); out = new PrintWriter( System.out ); solve(); f.close(); out.close(); System.exit( 0 ); } static boolean valid(int a, int b, int c) { return (a+b) > c && (b+c) > a && (a+c) > b; } /* static int nextA(int b, int c) { return Math.max(c + 1 - b, b + 1 - c); } static int nextB(int a, int c) { return Math.max(c + 1 - a, a + 1 - c); } static int nextC(int a, int b) { return Math.max(a + 1 - b, b + 1 - a); }*/ static class State { public int a_; public int b_; public int c_; public State(int a, int b, int c) { a_ = a; b_ = b; c_ = c; } } static HashMap<State, Integer> cache = new HashMap<State, Integer>(); static int INF = 999999; /* static int best(State s, int end) { System.out.println(s.a_ + " " + s.b_ + " " + s.c_); if (s.a_ == end && s.b_ == end && s.c_ == end) { return 0; } if (cache.containsKey(s)) { return cache.get(s); } //try reducing first side as much as possible int nextA = Math.max(nextA(s.b_, s.c_), end); int costFromA = INF; if (nextA < s.a_) { costFromA = best(new State(nextA, s.b_, s.c_), end); } int nextB = Math.max(nextB(s.a_, s.c_), end); int costFromB = INF; if (nextB < s.b_) { costFromB = best(new State(s.a_, nextB, s.c_), end); } int nextC = Math.max(nextC(s.a_, s.b_), end); int costFromC = INF; if (nextC < s.c_) { costFromC = best(new State(s.a_, s.b_, nextC), end); } int minCost = 1 + Math.min(Math.min(costFromA, costFromB), costFromC); cache.put(s, minCost); return minCost; }*/ final public static void solve() throws IOException { int start = nextInt(); int end = nextInt(); int a = end; int b = end; int c = end; int time = 0; while(a != start || b != start || c != start) { int nextA = Math.min(b + c - 1, start); int dA = nextA - a; int nextB = Math.min(a + c - 1, start); int dB = nextB - b; int nextC = Math.min(a + b - 1, start); int dC = nextC - c; //System.out.println( a + " " + b + " " + c ); //System.out.println(dA + " " + dB + " " + dC); if (dA >= dB && dA >= dC) { a += dA; ++time; } else if (dB >= dC && dB >= dA) { b += dB; ++time; } else { c += dC; ++time; } } //System.out.println(a + " " + b + " " + c); System.out.println(time); } final public static String nextToken() throws IOException { while ( st == null || !st.hasMoreTokens() ) { st = new StringTokenizer( f.readLine() ); } return st.nextToken(); } final public static int nextInt() throws IOException { return Integer.parseInt( nextToken() ); } final public static long nextLong() throws IOException { return Long.parseLong( nextToken() ); } final public static double nextDouble() throws IOException { return Double.parseDouble( nextToken() ); } final public static boolean nextBoolean() throws IOException { return Boolean.parseBoolean( 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
def get_next(T): [a,b,c] = sorted(T) return [b,c,b+c-1] def main(): y,x = [int(s) for s in input().split()] T = [x,x,x] i = 0 while max(T) < y: T = get_next(T) i += 1 print(2+i) 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
x, y = map(int, input().split()) cur = [y, y, y] count = 0 while cur[0] < x: cur[0] = cur[1] + cur[2] - 1 cur.sort() count += 1 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, i, j; long long ans = 0; cin >> x >> y; swap(x, y); multiset<int> second; second.insert(x); second.insert(x); second.insert(x); while (second.size() > 0) { int i = 0, a[5]; for (set<int>::iterator it = second.begin(); it != second.end(); it++) a[i++] = (*it); for (; i < 3; i++) a[i] = y; int dec = a[1] + a[2] - 1; ans++; second.erase(second.begin()); if (dec < y) second.insert(dec); } printf("%lld\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 main() { ios::sync_with_stdio(false); int a, b; cin >> a >> b; int t[3] = {b, b, b}; int ans = 0; while (t[0] != a || t[1] != a || t[2] != a) { ans++; sort(t, t + 3); t[0] = min(a, t[2] + t[1] - 1); } 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
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, e, p = 0, cnt = 0, q; scanf("%d%d", &a, &b); c = b; d = b; e = b; while (p != 3) { cnt++; q = (d + e) - 1; c = d; d = e; e = q; if (e >= a) e = a, p++; } printf("%d", cnt); }
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
initial, final = map(int, input().split()) arr = [final] * 3 ans = 0 while sum(arr) < 3*initial: arr.sort() arr[0] = min(initial, arr[1]+arr[2] - 1) 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 N = 1e6 + 7; struct tri { int d[3]; void init() { sort(d, d + 3); } } S, T; int main() { int x, y; scanf("%d%d", &x, &y); if (x > y) swap(x, y); S.d[0] = S.d[1] = S.d[2] = x; T.d[0] = T.d[1] = T.d[2] = y; int cnt = 0; while (S.d[0] != y) { int& a = S.d[0]; int sum = S.d[1] + S.d[2]; a = min(y, sum - 1); S.init(); cnt++; } printf("%d\n", cnt); }
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) { InputReader sc=new InputReader(System.in); int n=sc.nextInt(); //while(n<30){ int m=sc.nextInt(); if(m<n){ int t=m; m=n; n=t; } int i,a=n,b=n,c=n; int idx=0; for(i=0;;i++){ if(a==m && b==m && c==m){ break; } else{ if(idx==0){ a=Math.min(b+c-1, m); idx++; } else if(idx==1){ b=Math.min(a+c-1, m); idx++; } else if(idx==2){ c=Math.min(b+a-1, m); idx=0; } } } System.out.println(i); } static int max(int a,int b,int c){ if(a>=b && a>=c) return 0; else if(a<=c && b<=c) return 2; else return 1; } 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 String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(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; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || 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
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class Memory { public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int x=sc.nextInt(); int y=sc.nextInt(); int triangle[]= {y,y,y}; int count=0; while(triangle[0]!=x) { triangle[0]=Math.min(x, triangle[1]+triangle[2]-1); Arrays.sort(triangle); count++; } pw.println(count); pw.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(4000); } } }
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
n, m=map(int, input().split()) ans=0 t=[m]*3 while t!=[n]*3: t=sorted(t[1:]+[min(t[1]+t[2]-1, n)]) 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
import java.io.*; import java.util.*; /* * Heart beats fast * Colors and promises * How to be brave * How can I love when I am afraid to fall... */ public class Main { static final long mod=1000000007; static final double eps=1e-8; static final long inf=100000000000000000L; static final boolean debug=true; static Reader in=new Reader(); public static void main(String[] args) throws IOException { long fibo[]=new long[100]; fibo[0]=1; fibo[1]=2; for(int i=2; i<100;i++) fibo[i]=fibo[i-1]+fibo[i-2]; int x=ni(),y=ni(); int j=0; for(;j<100; j++) if(x<=fibo[j]*(y-1)+1) break; pr(j+2); System.out.println(ans); } static StringBuilder ans=new StringBuilder(); static long powm(long a, long b, long m) { long an=1; long c=a; while(b>0) { if(b%2==1) an=(an*c)%m; c=(c*c)%m; b>>=1; } return an; } static void pd(){if(debug)ans.append("hola");} static void pd(Object a){if(debug)ans.append(a+"\n");} static void pr(Object a){ans.append(a+"\n");} static void pr(){ans.append("\n");} static void p(Object a){ans.append(a);} static int ni(){return in.nextInt();} static long nl(){return in.nextLong();} static String ns(){return in.next();} static double nd(){return in.nextDouble();} static String pr(String a, long b) { String c=""; while(b>0) { if(b%2==1) c=c.concat(a); a=a.concat(a); b>>=1; } return c; } static class Reader { public BufferedReader reader; public StringTokenizer tokenizer; public Reader() { reader = new BufferedReader(new InputStreamReader(System.in), 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 a, b, c, n, m, t; int main() { cin >> n >> m; a = b = c = m; while (1) { if (a < n) { a = min(c + b - 1, n); t++; } if (b < n) { b = min(a + c - 1, n); t++; } if (c < n) { c = min(a + b - 1, n); t++; } if (a == b && b == c && c == n) break; } cout << t; 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; void abrir_entrada() {} int main() { int x, y; cin >> y >> x; int sol = 0; int a[3]; for (int i = 0; i < 3; i++) a[i] = x; while (a[2] < y) { a[2] = a[0] + a[1] - 1; swap(a[0], a[1]); swap(a[0], a[2]); sol++; } cout << sol << 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; using ll = long long; using ii = pair<ll, ll>; ll arr[3]; int main() { ll x, y; cin >> x >> y; for (int i = 0; i < 3; ++i) { arr[i] = y; } int moves = 0; while (arr[0] != x || arr[1] != x || arr[2] != x) { ii best(10000000, -1); for (int i = 0; i < 3; ++i) { if (arr[i] < best.first) { best.first = arr[i]; best.second = i; } } ll sum = 0; for (int i = 0; i < 3; ++i) { if (i == best.second) continue; sum += arr[i]; } sum -= 1; arr[best.second] = min(sum, x); ++moves; } cout << moves << "\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
#include <bits/stdc++.h> using namespace std; int main() { std ::ios ::sync_with_stdio(false); int x, y; while (cin >> x >> y) { x ^= y; y ^= x; x ^= y; int i = 0; int a = x; int b = 2 * x - 1; while (b < y) { int t = b; b = a + b - 1; a = t; i++; } cout << i + 3 << 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.*; public class Codeforces712C { public static int solve(int[] sides, int goal) { if(sides[0] == goal) return 0; else { int[] newT = new int[3]; newT[0] = sides[1]; newT[1] = sides[2]; newT[2] = Math.min(goal, sides[1] + sides[2] - 1); return 1 + solve(newT, goal); } } public static void main(String[] args) { try { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); int[] sides = new int[3]; for(int i = 0; i < 3; i++) sides[i] = y; System.out.println(solve(sides, x)); } catch(IOException e) { e.printStackTrace(); } } }
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()) besta=y bestb=y bestc=y time=0 while True: if besta>=x and bestb>=x and bestc>=x: print(time) break time+=1 if time%3==1: besta=bestb+bestc-1 elif time%3==2: bestb=besta+bestc-1 elif time%3==0: bestc=besta+bestb-1 #print("Status "+str(besta)+" "+str(bestb)+" "+str(bestc))
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.*; import java.util.*; public class C712 { public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(System.out); int x = input.nextInt(), y = input.nextInt(); int a = y, b = y, c = y; int res = 0; while(a != x) { //System.out.println(a+" "+b+" "+c); res++; if(a != x) { int next = a = Math.min(x, b+c-1); a = b; b = c; c = next; } } out.println(res); out.close(); } public static class input { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(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 Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } static long nextLong() throws IOException { 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
#include <bits/stdc++.h> using namespace std; int X, Y; int A[3]; int main() { cin >> X >> Y; if (X > Y) swap(X, Y); if (X == Y) { cout << 0; return 0; } A[0] = A[1] = A[2] = X; int y_count = 0; int i = 0; while (y_count != 3) { A[i % 3] = min(A[0] + A[1] + A[2] - A[i % 3] - 1, Y); if (A[i % 3] == Y) ++y_count; ++i; } cout << i; 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.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); StringTokenizer tk; tk = new StringTokenizer(in.readLine()); int x = parseInt(tk.nextToken()),y = parseInt(tk.nextToken()); int [] a = {y,y,y}; int cnt = 0; while(a[0]<x || a[1]<x || a[2]<x) { // System.out.println(a[0]+" , "+a[1]+" , "+a[2]); a[0] = min(x,a[1]+a[2]-1); Arrays.sort(a); 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class D2P3 { /** * How to read input in Java β€” tutorial <br /> * By Flatfoot<br /> * http://codeforces.com/blog/entry/7018 */ static class FastScanner { private BufferedReader br; private StringTokenizer st; FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new IllegalStateException(e); } return st.nextToken(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new IllegalStateException(e); } return str; } long nextLong() { return Long.parseLong(next()); } } /** * the entry point * * @param args */ public static void main(String args[]) { FastScanner cin = new FastScanner(); PrintWriter cout = new PrintWriter(System.out); solve(cin, cout); cout.flush(); } /** * C. Memory and De-Evolution * * @param cin * @param cout */ private static void solve(FastScanner cin, PrintWriter cout) { int x = cin.nextInt(); int y = cin.nextInt(); long ans = 0; int[] s = { y, y, y }; int mn = 0; while (x != s[0] || s[0] != s[1] || s[0] != s[2]) { // System.out.println(Arrays.toString(s)); int a = Math.abs(s[(mn + 1) % 3] + s[(mn + 2) % 3]) - 1; a = Math.min(a, x); s[mn] = a; if (s[(mn + 1) % 3] < s[(mn + 2) % 3]) mn = (mn + 1) % 3; else mn = (mn + 2) % 3; ans += 1; } cout.println(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
a,b=map(int,input().split()) l1=[a,a,a] l2=[b,b,b] ct=0 if a==b: print(0) else: while max(l2)!=a: l2.remove(min(l2)) s=sum(l2) d=abs(l2[0]-l2[1]) if d<a<s: l2.append(a) else: l2.append(s-1) ct+=1 print(ct+2)
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 int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2) % 1000000007; if (y % 2 == 0) return (temp * temp) % 1000000007; else { if (y > 0) return (((x * temp) % 1000000007) * temp) % 1000000007; else return (temp * temp) / x % 1000000007; } } long long int mul_inv(long long int n, long long int p, long long int m) { if (p == 1) { return n; } else if (p % 2 == 0) { long long int t = mul_inv(n, p / 2, m); return ((t) * (t)) % m; } else { long long int t = mul_inv(n, p / 2, m); return ((((n % m) * t) % m) * t) % m; } } bool isprime(long long int n) { if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (long long int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { return false; } } return true; } int main() { int x, y; cin >> x >> y; vector<int> v; v.push_back(y); v.push_back(y); v.push_back(y); int p = x; int ans = 0; while (1) { if (v[0] >= x) { break; } ans++; v[0] = v[1] + v[2] - 1; sort(v.begin(), v.end()); } 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
x, y = map(int, input().split()) assert y < x it = 0 a, b, c = y, y, y while True: assert a >= c >= b assert a + b > c assert a + c > b assert b + c > a b = a + c - 1 assert a + b > c assert a + c > b assert b + c > a it += 1 if b >= x: b = x break a, b, c = b, c, a b = x it += 1 assert a + b > c assert a + c > b assert b + c > a c = x it += 1 assert a + b > c assert a + c > b assert b + c > a print(it)
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
def f(n, m): ans=0 t=[m]*3 while t!=[n]*3: t=sorted(t[1:]+[min(t[1]+t[2]-1, n)]) ans+=1 return ans def g(n, m): ans=0 t=[n]*3 while t!=[m]*3: t=sorted(t[:2]+[max(t[1]-t[0]+1, m)]) ans+=1 return ans n, m=map(int, input().split()) print(min(f(n, m), g(n, m)))
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
a,b = map(int,raw_input().split()) c = 2*b-1 i =2 while c<a: b,c = c,b+c-1 i+=1 #print a,c print i+1
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 y, x; while (~scanf("%d%d", &y, &x)) { int a[5]; for (int i = 0; i < 3; i++) a[i] = x; int ans = 0; while (1) { int flag = 1; for (int i = 0; i < 3; i++) if (a[i] < y) flag = 0; if (flag) break; ans++; int minn = 1e6, sum = 0; for (int i = 0; i < 3; i++) { sum += a[i]; minn = min(minn, a[i]); } for (int i = 0; i < 3; i++) { if (a[i] == minn) { a[i] = min(y, sum - minn - 1); break; } } } 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
x,y=map(int,input().split()) a,b,c=y,y,y k=0 while a!=x:a,b,c=sorted([min(x,b+c-1),b,c]);k+=1 print(k)
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; cin >> x >> y; int besta = y, bestb = y, bestc = y; int turns = 0; while (true) { if (besta >= x && bestb >= x && bestc >= x) { cout << turns << endl; break; } turns++; if (turns % 3 == 1) besta = bestb + bestc - 1; if (turns % 3 == 2) bestb = besta + bestc - 1; if (turns % 3 == 0) bestc = besta + bestb - 1; } }
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()) s = [y,y,y] k = 0 while sum(s)!=x*3: minn = min(s) maxx = max(s) sr = sum(s)-maxx-minn a = sum([sr,maxx])-1 if a>x: a = x s[s.index(minn)] = a k+=1 print(k)
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; public class Round370C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x = in.nextInt(); int y = in.nextInt(); int[] triangle = new int[3]; Arrays.fill(triangle, y); int count = 0; int round = 2; while (triangle[0] < x || triangle[1] < x || triangle[2] < x) { if (round == 2) { triangle[round] = triangle[0] + triangle[1] - 1; round = 1; } else if (round == 1) { triangle[round] = triangle[0] + triangle[2] - 1; round = 0; } else if (round == 0) { triangle[round] = triangle[1] + triangle[2] - 1; round = 2; } 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
from math import sqrt import sys x, y = [int(i) for i in input().split()] a = y b = y c = y count = 0 while a != x or b != x or c != x: min_side = min(min(a, b), c) max_side = max(max(a, b), c) mid_side = a+b+c-max_side-min_side new_side = min(max_side + mid_side - 1, x) a = mid_side b = max_side c = new_side # print(a, b, c) count += 1 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 m[5]; int main() { int a, b; scanf("%d %d", &a, &b); if (a > b) swap(a, b); m[0] = m[1] = m[2] = a; int res = 0; while (m[0] < b || m[1] < b || m[2] < b) { sort(m, m + 3); m[0] = (m[1] + m[2] - 1); res++; } 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
#!/usr/bin/env python #-*-coding:utf-8 -*- x,y=map(int,input().split()) N=3 L=N*[y] y=i=0 while x>L[i]: j=(1+i)%N L[i]=L[(i-1)%N]-1+L[j] i=j y+=1 print(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
def read(t=None): string = raw_input() return string if t is None else [t(x) for x in string.split()] def printl(l): for x in l: print x, print if __name__ == "__main__": a, b = read(int) t = [b for i in range(3)] n = 0 while t[2] != a: #print t t[0] = min(t[1]+t[2]-1, a) n += 1 t = sorted(t) print n+2 if n != 0 else 0
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
n, m=map(int, input().split()) ans=0 t=[m]*3 while t!=[n]*3: t=t[1:]+[min(t[1]+t[2]-1, n)] 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
from sys import stdin,stdout,setrecursionlimit,maxint,exit #setrecursionlimit(2*10**5) def listInput(): return map(long,stdin.readline().split()) def printBS(li): for i in xrange(len(li)-1): stdout.write("%d "%li[i]) stdout.write("%d\n"%li[-1]) def sin(): return stdin.readline().rstrip() x,y=listInput() #think the problem in reverse #from a traingle of side y...make a triangle of side x #by increasing the sides length #use greedy approach i.e. #since from trianglr inequality #a<b+c # can increase a to b+c-1 in one step at max a,b,c,=y,y,y turns=0 while True: if a>=x and b>=x and c>=x: print turns break turns+=1 if turns%3==1: a=b+c-1 elif turns%3==2: b=a+c-1 else: c=a+b-1
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> long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int exp(long long int x, long long int y, long long int mod) { long long int res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } long long int modinverse(long long int x, long long int mod) { return exp(x, mod - 2, mod); } using namespace std; const long long int inf = 0x3f3f3f3f3f3f3f3fll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int x, y, ans = 0; cin >> x >> y; vector<long long int> v; for (long long int i = 0; i < 3; i++) v.push_back(y); sort(v.begin(), v.end()); while (v[0] != v[1] || v[1] != v[2] || v[0] != x) { ans++; v[0] = min(x, v[1] + v[2] - 1); sort(v.begin(), v.end()); } 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
x, y = [int(s) for s in raw_input().split()] t = [y, y, y] ans = 0 while t[0] != x : ans += 1 t[0] = min(x, t[1] + t[2] - 1) t.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; float time_taken(float x1, float y1, float x2, float y2, float s) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)) / s; } int bs_lessthan(int a[], int low, int high, int n, int key) { int mid = (low + high) / 2; if (low > high) return -1; if ((mid == n - 1 && a[mid] <= key) || (a[mid] <= key && a[mid + 1] > key)) return mid; else if (a[mid] > key) return bs_lessthan(a, low, mid - 1, n, key); else return bs_lessthan(a, mid + 1, high, n, key); } void print_array(int a[], int n) { int i; for (i = 0; i < n; i++) cout << a[i] << " "; cout << endl; } bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) { return a.second < b.second; } int main() { string s; int x, y, a, b, c, count = 0; cin >> x >> y; if (x == y) { cout << "0\n"; return 0; } a = b = c = y; while (a < x) { c = b; b = a; a = b + c - 1; count++; } cout << count + 2 << 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; void solve() { long long int a, b; cin >> a >> b; vector<long long int> ar(3, b); long long int cnt = 0; while (1) { if (ar[0] >= a && ar[1] >= a && ar[2] >= a) { cout << cnt << "\n"; break; } cnt++; if (cnt % 3 == 0) ar[0] = ar[1] + ar[2] - 1; if (cnt % 3 == 1) ar[1] = ar[2] + ar[0] - 1; if (cnt % 3 == 2) ar[2] = ar[0] + ar[1] - 1; } return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc; tc = 1; while (tc--) { 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.*; import java.util.*; import java.lang.*; public class Rextester{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); br.close(); int n = new Integer(st.nextToken()); int m = new Integer(st.nextToken()); int a = m,b = m,c = m; int ans = 0; while(true){ int x = a,y=b,z=c; int w = a+b; w--; a = w; b = x; c = y; if(a>=n||b>=n||c>=n){ break; } else{ ans++; } } ans+=3; System.out.println(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 n, m; int x[4]; int check(int x[], int a) { for (int i = 0; i < 3; i++) if (x[i] <= a) return false; return true; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < 3; i++) x[i] = m; sort(x, x + 3); int ret = 0; while (!check(x, n)) { sort(x, x + 3); x[0] = x[1] + x[2] - 1; ret++; } cout << ret << 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.*; public class C { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int a = sc.nextInt(), b = sc.nextInt(); ArrayList<Integer> inp = new ArrayList<Integer>(); inp.add(b); inp.add(b); inp.add(b); Collections.sort(inp); int ans = 0; while(true) { //System.out.printf("%d %d %d %d\n", inp.get(0), inp.get(1), inp.get(2), a); if( inp.get(0).intValue() == inp.get(1).intValue() && inp.get(1).intValue() == inp.get(2).intValue() && inp.get(0).intValue() == a ) break; ans++; inp.remove(0); inp.add(Math.min(inp.get(0) + inp.get(1) - 1, a)); Collections.sort(inp); } out.println(ans); out.close(); } // PrintWriter for faster output public static PrintWriter out; // MyScanner class for faster input public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } boolean hasNext() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { return false; } } return true; } String next() { if (hasNext()) return st.nextToken(); return null; } 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 n, m; cin >> n >> m; int a[3]; a[0] = a[1] = a[2] = m; int count = 0; sort(a, a + 3); while (a[0] != n) { int si = a[1] + a[2]; a[0] = (si - 1 > n) ? n : (si - 1); count++; sort(a, a + 3); } 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
import java.io.*; import java.math.BigInteger; import java.util.*; public class C { String line; StringTokenizer inputParser; BufferedReader is; FileInputStream fstream; DataInputStream in; String FInput=""; void openInput(String file) { if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin else { try{ fstream = new FileInputStream(file); in = new DataInputStream(fstream); is = new BufferedReader(new InputStreamReader(in)); }catch(Exception e) { System.err.println(e); } } } void readNextLine() { try { line = is.readLine(); inputParser = new StringTokenizer(line, " "); //System.err.println("Input: " + line); } catch (IOException e) { System.err.println("Unexpected IO ERROR: " + e); } } int NextInt() { String n = inputParser.nextToken(); int val = Integer.parseInt(n); //System.out.println("I read this number: " + val); return val; } private double NextDouble() { String n = inputParser.nextToken(); double val = Double.parseDouble(n); return val; } String NextString() { String n = inputParser.nextToken(); return n; } void closeInput() { try { is.close(); } catch (IOException e) { System.err.println("Unexpected IO ERROR: " + e); } } public void readFInput() { for(;;) { try { readNextLine(); FInput+=line+" "; } catch(Exception e) { break; } } inputParser = new StringTokenizer(FInput, " "); } long NextLong() { String n = inputParser.nextToken(); long val = Long.parseLong(n); return val; } public static void main(String [] argv) { //String filePath="input.txt"; String filePath=null; if(argv.length>0)filePath=argv[0]; new C(filePath); } public C(String inputFile) { openInput(inputFile); //readNextLine(); int T=1;//NextInt(); StringBuilder sb = new StringBuilder(); long startT = System.currentTimeMillis(); for(int t=1; t<=T; t++) { readNextLine(); int N=NextInt(); int K=NextInt(); int [] c = new int[3]; for(int i=0; i<3; i++) { c[i] = K; } int ans=0; do{ c[0]=c[1]+c[2]-1; Arrays.sort(c); ans++; }while(c[0]<N); sb.append(ans); } System.out.print(sb); closeInput(); } }
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
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package javaapplication1; import java.util.Scanner; /** * * @author TaMeEm */ public class JavaApplication1 { /** * @param args the command line arguments */ public static int swap(int x,int y) { return x; } public static void main(String[] args) { // TODO code application logic here int x,y; Scanner in=new Scanner(System.in); x=in.nextInt(); y=in.nextInt(); int a=y,b=y,c=y; int cnt=0; while(a<x) { c=a+b-1; a=swap(c,c=a); if(c>b) b=swap(c,c=b); cnt++; } System.out.println(cnt+2); } }
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.io.*; import java.lang.*; public class test5 { public static void main(String args[]){ MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int initlength = sc.nextInt(); int finlength = sc.nextInt(); int holder = 0; int max = 0; int min = 0; int middle = 0; int seconds = 0; boolean toggle = true; if(finlength == initlength){ toggle = false; } else if(initlength < finlength){ max = initlength; min = initlength; middle = initlength; } else{ max = finlength; min = finlength; middle = finlength; finlength = initlength; } while(toggle){ if(finlength < max + middle) { seconds += 3; toggle = false; } else if(finlength == max + middle) { seconds += 4; toggle = false; } else if(finlength > max + middle) { holder = max; max = max + middle - 1; min = middle; middle = holder; seconds++; } } System.out.println(seconds); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------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; } } } /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String */
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()) t=0 ba=y bb=y bc=y while True: if (ba >= x and bb >= x and bc >= x): print(t) break t+=1 if t%3==1: ba = bb + bc - 1 if t % 3 == 2: bb = ba + bc - 1 if t%3==0: bc = ba + bb - 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; template <class A> ostream& operator<<(ostream& out, const vector<A>& v) { for (long long i = 0; i < v.size(); i++) { if (i) out << " "; out << v[i]; } return out << '\n'; } long long mod = 1000000007; inline long long add(long long a, long long b) { a += b; if (a >= mod) a -= mod; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += mod; return a; } inline long long mul(long long a, long long b) { return (a * 1ll * b) % mod; } inline long long powmod(long long a, long long b) { long long rt = 1; while (b > 0) { if (b & 1) rt = mul(rt, a); a = mul(a, a); b >>= 1; } return rt; } inline long long inv(long long a) { return powmod(a, mod - 2); } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } const long long N = 1e5 + 7; long long a[N]; long long n; void solve() { long long x, y; cin >> x >> y; a[0] = 1; a[1] = 2; for (long long i = 2; i < 51; i++) { a[i] = a[i - 1] + a[i - 2]; } long long count = 2; long long start = y; long long i = 1; long long xx = y; long long lx = 0; long long ly = 0; while (y < x) { y = (a[i] * xx - (lx + ly + 1)); swap(lx, ly); ly = lx + ly + 1; i++; count++; if (false) cerr << y << " "; } cout << count << '\n'; } int32_t main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL), cout << setprecision(14); ; long long t = 1; while (t--) { solve(); } }
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.Arrays; import java.util.Scanner; public class Main { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { int x = scanner.nextInt(), y = scanner.nextInt(); long output = 0; int[] lol = {y, y, y}; while (lol[0] != x || lol[1] != x || lol[2] != x) { lol[0] = Math.min(lol[1] + lol[2] - 1, x); Arrays.sort(lol); output++; } System.out.print(output); } }
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_base::sync_with_stdio(false); int x, y; cin >> x >> y; int arr[3] = {y, y, y}; int counter = 0; while (arr[0] != x) { int temp1 = arr[1]; int temp2 = arr[2]; arr[0] = temp1; arr[1] = temp2; arr[2] = min(x, arr[0] + arr[1] - 1); counter++; } cout << counter << 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 = map(int,input().split()) ar = [y,y,y] ans = 0 while min(ar) < x: ar.sort() ar[0] = ar[1] + ar[2] - 1 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; int main() { int x, y, a, b, c, num = 0; scanf("%d%d", &x, &y); a = b = c = y; while (a < x || b < x || c < x) { if (a <= b && a <= c) a = b + c - 1; else if (b <= a && b <= c) b = a + c - 1; else c = a + b - 1; num++; } printf("%d", num); }
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> long long int power(long long int x, long long int b) { long long int p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= 9000000000000000000; } b >>= 1; x *= x; x %= 9000000000000000000; } return p % 9000000000000000000; } using namespace std; struct lex_compare { bool operator()(const pair<long double, long long int> p1, const pair<long double, long long int> p2) { return (p1.first == p2.first) ? p1.second < p2.second : p1.first > p2.first; } }; long long int divd(long long int a, long long int b, long long int m) { return (b / m) - (a - 1) / m; } long long int rec(long long int arr[], long long int y) { sort(arr, arr + 3); if (arr[0] == y && arr[1] == y && arr[2] == y) return 0; if (arr[2] > y) return 1e15; arr[0] = min(arr[1] + arr[2] - 1, y); return 1 + rec(arr, y); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int x, y; cin >> x >> y; long long int arr[3] = {y, y, y}; long long int ans = rec(arr, x); cout << ans << "\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.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int t = 0; int s1 = y, s2= y, s3= y; int m = 0; while(s1< x|| s2<x||s3<x){ if(m == 0){ int max = Math.max(s2, s3); int min = Math.min(s2, s3); s1 = Math.min(x, max+min-1); }else if( m == 1){ int max = Math.max(s1, s3); int min = Math.min(s1, s3); s2 = Math.min(x, max+min-1); }else{ int max = Math.max(s2, s1); int min = Math.min(s2, s1); s3 = Math.min(x, max+min-1); } t++; m = (m+1)%3; // System.out.println(s1+" "+s2+" "+s3); } System.out.println(t); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
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 class CodeForces { private final BufferedReader reader; private final PrintWriter writer; private StringTokenizer tokenizer; private void solve() { int x = nextInt(); int y = nextInt(); int[] xs = new int[]{x, x, x}; int[] ys = new int[]{y, y, y}; int d, next; int index = 0; int res = 0; while (ys[0] != x || ys[1] != x || ys[2] != x) { d = -1; for (int i = 0; i < 3; i++) { next = ys[(i + 1) % 3] + ys[(i + 2) % 3] - ys[i] - 1; if (next > d) { index = i; d = next; } } ys[index] += (Math.min(d, x - ys[index])); res++; } writer.print(res); } public static void main(String[] args) { new CodeForces(System.in, System.out); } private CodeForces(InputStream inputStream, OutputStream outputStream) { this.reader = new BufferedReader(new InputStreamReader(inputStream)); this.writer = new PrintWriter(outputStream); solve(); writer.close(); } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(readLine()); } return tokenizer.nextToken(); } private String readLine() { String line; try { line = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return line; } private int nextInt() { return Integer.parseInt(next()); } private long nextLong() { return Long.parseLong(next()); } private double nextDouble() { return Double.parseDouble(next()); } private void shuffleArray(int[] a) { Random r = new Random(); int tmp; for (int i = 1; i < a.length; i++) { tmp = r.nextInt(i + 1); int val = a[tmp]; a[tmp] = a[i]; a[i] = val; } } }
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 class Main { static int a,b,c; public static void main(String[] args) { FastScanner3 sc = new FastScanner3(System.in); a = sc.nextInt(); b = c = a; int goal = sc.nextInt(); int ctr = 0; int[] arr = new int[]{goal, goal, goal}; goal = a; while(arr[0] != goal || arr[1] != goal || arr[2] != goal){ Arrays.sort(arr); // System.out.println(Arrays.toString(arr)); // int tmp = lowerSide(arr[2], arr[0], arr[1]); int tmp = biggestSide(arr[0], arr[1], arr[2]); // System.out.println(tmp); arr[0] = Math.min(tmp, goal); if(arr[2] == arr[1] && arr[2] + arr[1] == arr[0]) arr[2]--; else if(arr[2] == arr[0] && arr[2] + arr[0] == arr[1]) arr[2]--; else if(arr[1] == arr[0] && arr[1] + arr[0] == arr[2]) arr[2]--; ctr++; } System.out.println(ctr); } static int biggestSide(int x, int y, int z){ int tmp = (y + z); tmp -= 1; return tmp; } static int lowerSide(int x, int y, int z){ int tmp = Math.abs(y - z); tmp += 1; return tmp; } } class FastScanner3{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastScanner3(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 String next() { 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 String nextLine() { int c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isLineEndChar(c)); return res.toString(); } public double nextDouble() { 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, nextInt()); 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, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } 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 boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isLineEndChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == '\n' || c == '\r' || 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; const int MAXN = 101; const int MOD = 1000000007; const double PI = 4 * atan(1); int sides[3]; int x, y; bool desired() { if (sides[0] == sides[1] && sides[1] == sides[2] && sides[2] == x) { return true; } return false; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> x >> y; sides[0] = y; sides[1] = y; sides[2] = y; int count = 0; while (!desired()) { sides[0] = sides[1] + sides[2] - 1; swap(sides[0], sides[1]); swap(sides[1], sides[2]); if (sides[2] > x) { sides[2] = x; } count++; } cout << count; 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.*; import java.util.LinkedList; public class test3 { public static void main(String [] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int arr[]=new int[3]; arr[0]=b; arr[1]=b; arr[2]=b; int sum=0; int count=0; int a2=0; while(count<3){ if(a2%3==0&&arr[0]!=a){ int b2=arr[1]+arr[2]-1; if(b2>=a){ arr[0]=a; count++; } else{ arr[0]=b2; } sum++; } else{ if(a2%3==1&&arr[1]!=a){ int b2=arr[0]+arr[2]-1; if(b2>=a){ arr[1]=a; count++; } else{ arr[1]=b2; } sum++; } else{ if(a2%3==2&&arr[2]!=a){ int b2=arr[0]+arr[1]-1; if(b2>=a){ arr[2]=a; count++; } else{ arr[2]=b2; } sum++; } } } a2++; } System.out.println(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, input().split()) if (x > y): x, y = y, x a = x b = x c = x ans = 0 while not (a == b == c == y): if (a <= b and a <= c): a = min(b + c - 1, y) elif (b <= a and b <= c): b = min(a + c - 1, y) elif (c <= a and c <= b): c = min(a + b - 1, y) 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; int main() { long n, m; while (cin >> n >> m) { long cnt = 0, ar[10] = {0}, k = 0; ar[0] = m; ar[1] = m; ar[2] = m; while (1) { sort(ar, ar + 3); if (ar[0] >= n) break; ar[0] = min(n, ar[1] + ar[2] - 1); cnt++; } 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
import math def inp(): return int(raw_input()) def linp(): return map(int, raw_input().split()) X, Y = linp() x=max(X, Y) y=min(X, Y) li=[y, y, y] ans=0 while li!=[x, x, x]: a, b, c=li[0], li[1], li[2] #print li if c!=x: temp=b b=c c=min(x, temp+c-1) ans+=1 li=[a, b, c] li.sort() continue if b!=x: a=b b=min(x, c+b-1) ans+=1 li=[a, b, c] li.sort() continue if a!=x: a=x ans+=1 li=[a, b, c] li.sort() continue 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 arr[3] = {y, y, y}; int cnt = 0; while (arr[0] != x || arr[1] != x || arr[2] != x) { ++cnt; arr[0] = min(x, arr[1] + arr[2] - 1); sort(arr, arr + 3); } cout << 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
import java.io.*; import java.util.*; public class MemoryAndDeEvolution { static long countTime = 0; public static void evlove(long[] arr, long s2, long s1){ if(s2 == s1) return; while(arr[0]!=s1 || arr[1]!=s1 || arr[2]!=s1){ countTime++; arr[0] = Math.min(s1,arr[1]+arr[2]-1); sort(arr); } } public static void sort(long[] ar){ long min; for(int i=0;i<2;i++){ if(ar[i]>ar[i+1]){ min = ar[i]; ar[i] = ar[i+1]; ar[i+1] = min; } } } 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[] = new long[3] ; a1[0] = a1[1] = a1[2] = s2; if(s1>s2){ evlove(a1, s2,s1); } else{ evlove(a1, 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class MemoryAndDeevolution { 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[] sides = new int[]{ y, y, y }; int time = 0; while (true) { if (sides[0] == sides[1] && sides[1] == sides[2] && sides[2] == x) { break; } int min = sides[1]; int max = sides[2]; int next = Math.min(x, max + min - 1); sides[0] = min; sides[1] = max; sides[2] = next; time++; } System.out.println(time); } }
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 class memoryDevolution { static boolean checkTriangle(int a, int b, int c) { if (a+b > c && c+a > b && b+c > a) return true; else return false; } static int x; static int y; static int [] sides; public static void main(String args[])throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); x = sc.nextInt(); y = sc.nextInt(); sides = new int[3]; for (int i = 0; i<3; i++) sides[i] = y; boolean allSides = false; int time = 0; while (allSides == false) { sides[0] = sides[1]+sides[2]-1; time++; if (sides[0] >= x && sides[1] >= x && sides[2]>=x) break; sides[1] = sides[0]+sides[2]-1; time++; if (sides[0] >= x && sides[1] >= x && sides[2]>=x) break; sides[2] = sides[1]+sides[0]-1; time++; if (sides[0] >= x && sides[1] >= x && sides[2]>=x) break; } out.println(time); out.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.io.*; import java.math.*; import java.util.*; public class Main { private static char [] pair = new char[128]; private static char [] C,S; private static int [] cnt; private static void compress(){ int m = 0; char lst = 0; for (int i = 0;i < S.length;i++){ if (lst != S[i]) m++; lst = S[i]; } C = new char[m]; cnt = new int[m]; m = 0; for (int i = 0;i < S.length;) { int j = i; while (j < S.length && S[i] == S[j]) j++; C[m] = S[i]; cnt[m] = j - i; m++; i = j; } } public static void main(String[] args) throws Exception{ IO io = new IO(null,null); int x = io.getNextInt(),y = io.getNextInt(),ans = 0; int [] A = {y,y,y}; while (A[0] != x || A[1] != x || A[2] != x) { int ch = 0,best = 0; for (int c = 0;c < 3;c++){ int o = (c == 0) ? 1 : 0,t = 3 - o - c; int l = Math.abs(A[o] - A[t]),u = A[o] + A[t],v = u - 1; if (l < x && x < u) v = x; int diff = v - A[c]; if (diff > best) { best = diff; ch = c; } } int o = (ch == 0) ? 1 : 0,t = 3 - o - ch; int l = Math.abs(A[o] - A[t]),u = A[o] + A[t],v = u - 1; if (l < x && x < u) v = x; A[ch] = v; ans++; // System.err.println(Arrays.toString(A)); } io.println(ans); io.close(); } } class IO{ private BufferedReader br; private StringTokenizer st; private PrintWriter writer; private String inputFile,outputFile; public boolean hasMore() throws IOException{ if(st != null && st.hasMoreTokens()) return true; if(br != null && br.ready()) return true; return false; } public String getNext() throws FileNotFoundException, IOException{ while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String getNextLine() throws FileNotFoundException, IOException{ return br.readLine().trim(); } public int getNextInt() throws FileNotFoundException, IOException{ return Integer.parseInt(getNext()); } public long getNextLong() throws FileNotFoundException, IOException{ return Long.parseLong(getNext()); } public void print(double x,int num_digits) throws IOException{ writer.printf("%." + num_digits + "f" ,x); } public void println(double x,int num_digits) throws IOException{ writer.printf("%." + num_digits + "f\n" ,x); } public void print(Object o) throws IOException{ writer.print(o.toString()); } public void println(Object o) throws IOException{ writer.println(o.toString()); } public IO(String x,String y) throws FileNotFoundException, IOException{ inputFile = x; outputFile = y; if(x != null) br = new BufferedReader(new FileReader(inputFile)); else br = new BufferedReader(new InputStreamReader(System.in)); if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); else writer = new PrintWriter(new OutputStreamWriter(System.out)); } protected void close() throws IOException{ br.close(); writer.close(); } public void outputArr(Object [] A) throws IOException{ int L = A.length; for (int i = 0;i < L;i++) { if(i > 0) writer.print(" "); writer.print(A[i]); } writer.print("\n"); } }
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.*; import static java.lang.Math.*; public class Main { FastScanner in; PrintWriter out; static final String FILE = ""; void solve() { int[] ms = new int[3]; int x = in.nextInt(), y = in.nextInt(); for (int i = 0; i < 3; i++) ms[i] = y; for (int i = 1; ; i++) { Arrays.sort(ms); ms[0] = min(x, ms[1] + ms[2] - 1); if (ms[0] == x && ms[1] == x && ms[2] == x) { out.print(i); return; } } } public void run() { if (FILE.equals("")) { in = new FastScanner(System.in); out = new PrintWriter(System.out); } else { try { in = new FastScanner(new FileInputStream(FILE + ".in")); out = new PrintWriter(new FileOutputStream(FILE + ".out")); } catch (FileNotFoundException e) { e.printStackTrace(); } } solve(); out.close(); } public static void main(String[] args) { (new Main()).run(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { st = null; try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); return null; } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public float nextFloat() { return Float.parseFloat(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; const long long N = 1e6 + 100, INF = 1e9 + 7, P = 1e9 + 7; int n, m, cnt, t[5]; int main() { cin >> n >> m; t[1] = t[2] = t[3] = m; while (t[1] != n) { cnt++; t[1] = min(t[2] + t[3] - 1, n); sort(t + 1, t + 4); } cout << cnt; }
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
s, e = map(int,input().split()) a = [e] * 3 ans = 0 sum = 0 while sum != 2: temp = a[1] + a[2] if temp - 1 >= s: a[0] = s sum += 1 else: a[0] = temp - 1 a.sort() ans += 1 print(ans + 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; int main() { int a, b; cin >> a >> b; int cnt = 0; if (a > b) swap(a, b); int first = a, second = a; while (first + second <= b) { int temp = first + second - 1; second = first; first = temp; cnt++; } cnt += 3; cout << cnt << "\n"; }
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(); int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; } long long ar[3]; void solve() { long long x, y, ans = 0; cin >> x >> y; ar[0] = ar[1] = ar[2] = y; while (ar[0] < x || ar[1] < x || ar[2] < x) { sort(ar, ar + 3); ar[0] = ar[1] + ar[2] - 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
import java.util.*; import java.io.*; public class Memory_and_DeEvolution { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); f.close(); PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); pq.add(y); pq.add(y); pq.add(y); int ans = 0; while (true) { int a = pq.poll(); int b = pq.poll(); int c = pq.poll(); if (a == x && b == x && c == x) { break; } ans++; a = b + c - 1; if (a > x) { a = x; } pq.add(a); pq.add(b); pq.add(c); } System.out.println(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
x, y = [int(i) for i in input().split()] if x > y: t = x x = y y = t a = [x, x, x] ans = 0 while a[0] != y or a[1] != y or a[2] != y: a[0] = min(a[1] + a[2] - 1, y) a.sort() 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 leto; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; public class letnee4 { public static void main(String[] args) throws FileNotFoundException { //Scanner scan = new Scanner(new File("power.in")); Scanner scan = new Scanner(System.in); //PrintWriter out = new PrintWriter("power.out"); int x = scan.nextInt(); int y = scan.nextInt(); int []a = new int [1000000]; int n = 3; a[1] = y; a[2] = y; a[3] = y; while((a[n] != x)||(a[n-1] != x)||(a[n-2] != x)){ n++; a[n] = a[n-1]+a[n-2]-1; if(a[n] >x){ a[n] = x; } } System.out.print(n-3); //out.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
#include <bits/stdc++.h> using namespace std; int arr[3]; int f, t; int main() { while (cin >> f >> t) { arr[0] = arr[1] = arr[2] = t; int res = 0; while (arr[0] < f || arr[1] < f || arr[2] < f) { sort(arr, arr + 3); arr[0] = min(arr[1] + arr[2] - 1, f); res++; } cout << res << '\n'; } return 0; }
CPP