Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; public class C { public static void solution(BufferedReader reader, PrintWriter writer) throws IOException { In in = new In(reader); Out out = new Out(writer); int x = in.nextInt(), y = in.nextInt(); int cnt = 0; int[] a = new int[] { y, y, y }; while (a[0] < x) { a[0] = Math.min(x, a[1] + a[2] - 1); Arrays.sort(a); cnt++; } out.println(cnt); } public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader( new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out))); solution(reader, writer); writer.close(); } protected static class In { private BufferedReader reader; private StringTokenizer tokenizer = new StringTokenizer(""); public In(BufferedReader reader) { this.reader = reader; } public String next() throws IOException { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public int[] nextIntArray1(int n) throws IOException { int[] a = new int[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextInt(); return a; } public int[] nextIntArraySorted(int n) throws IOException { int[] a = nextIntArray(n); Random r = new Random(); for (int i = 0; i < n; i++) { int j = i + r.nextInt(n - i); int t = a[i]; a[i] = a[j]; a[j] = t; } Arrays.sort(a); return a; } public long[] nextLongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public long[] nextLongArray1(int n) throws IOException { long[] a = new long[n + 1]; for (int i = 1; i <= n; i++) a[i] = nextLong(); return a; } public long[] nextLongArraySorted(int n) throws IOException { long[] a = nextLongArray(n); Random r = new Random(); for (int i = 0; i < n; i++) { int j = i + r.nextInt(n - i); long t = a[i]; a[i] = a[j]; a[j] = t; } Arrays.sort(a); return a; } } protected static class Out { private PrintWriter writer; private static boolean local = System .getProperty("ONLINE_JUDGE") == null; public Out(PrintWriter writer) { this.writer = writer; } public void print(char c) { writer.print(c); } public void print(int a) { writer.print(a); } public void println(Object a) { writer.println(a); } public void println(Object[] os) { for (int i = 0; i < os.length; i++) { writer.print(os[i]); writer.print(' '); } writer.println(); } public void println(int[] a) { for (int i = 0; i < a.length; i++) { writer.print(a[i]); writer.print(' '); } writer.println(); } public void println(long[] a) { for (int i = 0; i < a.length; i++) { writer.print(a[i]); writer.print(' '); } writer.println(); } public static void db(Object... objects) { if (local) System.out.println(Arrays.deepToString(objects)); } } }
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 java.math.*; public class Main { FastScanner in; PrintWriter out; static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = null; } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { if (st == null || !st.hasMoreTokens()) return br.readLine(); StringBuilder result = new StringBuilder(st.nextToken()); while (st.hasMoreTokens()) { result.append(" "); result.append(st.nextToken()); } return result.toString(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } void run() throws IOException { in = new FastScanner(System.in); out = new PrintWriter(System.out, false); solve(); out.close(); } public static void main(String[] args) throws IOException{ new Main().run(); } public void printArr(int[] arr){ for(int i = 0; i < arr.length; i++){ out.print(arr[i] + " "); } out.println(); } public long gcd(long a, long b){ if(a == 0) return b; return gcd(b % a, a); } public void solve() throws IOException{ int x = in.nextInt(), y = in.nextInt(); int res = 0; int[] arr = new int[]{y, y, y}; while(arr[0] != x || arr[1] != x || arr[2] != x){ res++; arr[0] = Math.min(x, arr[1] + arr[2] - 1); Arrays.sort(arr); } out.println(res); } }
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()) ans = 0 a=b=c=y while not (a>=x and b>=x and c>=x): if ans%3==0: a = b+c-1 elif ans%3==1: b = a+c-1 else: c = a+b-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> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; bool check(vector<int> a, int y) { return a[0] == y && a[1] == y && a[2] == y; } int get_sum(vector<int> a) { int m = *min_element(a.begin(), a.end()); for (int i = 0; i < 3; i++) { if (a[i] == m) { for (int j = i; j < 3 - 1; j++) { a[j] = a[j + 1]; } a.pop_back(); break; } } return a[0] + a[1]; } int get_min_idx(vector<int> a) { int m = min(a[0], min(a[1], a[2])); for (int i = 0; i < 3; i++) { if (a[i] == m) return i; } } int main() { int x, y; cin >> x >> y; vector<int> a(3, y); int cnt = 0; while (!check(a, x)) { cnt++; a[get_min_idx(a)] = min(get_sum(a) - 1, x); } cout << cnt << 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.BufferedReader; import java.io.InputStreamReader; public class C { static class N implements Comparable<N> { int x, y; N(int a, int b) { x = a; y = b; } @Override public int compareTo(N o) { return Integer.compare(x, o.x); } } public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String[] l = bf.readLine().split(" "); int x = Integer.parseInt(l[0]); int y = Integer.parseInt(l[1]); int t1[] = new int[] { y, y, y }; int diff, bestInd, bestDiff, total, ans = 0; while (!check(t1, x)) { total = 0; for (int i = 0; i < t1.length; i++) { total += t1[i]; } diff = 0; bestInd = 0; bestDiff = 0; for (int i = 0; i < t1.length; i++) { diff = total - t1[i] - 1; diff = Math.min(diff, x) - t1[i]; if (diff > bestDiff) { bestInd = i; bestDiff = diff; } } t1[bestInd] += bestDiff; ans++; } System.out.println(ans); } private static boolean check(int[] t1, int x) { for (int y : t1) if (y != x) return false; return true; } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.awt.*; import java.io.*; import java.util.*; public class Abc { public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int x=sc.nextInt(),y=sc.nextInt(); int cnt=0,a=y,b=y,c=y; while (true){ if (Math.min(Math.min(a,b),c)>=x){ System.out.println(cnt); break; } if (cnt%3==0){ a=b+c-1; }else if (cnt%3==1){ b=a+c-1; }else { c=a+b-1; } cnt++; } } 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; } } }
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 triangle(sides, goal): ordered = sorted(sides) if ordered[0] == goal and ordered[2] == goal: return 0 ordered[0] = min(ordered[2]+ordered[1]-1, goal) return 1 + triangle(ordered, goal) x,y = map(int,raw_input().split()) print triangle([y,y,y],x)
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 a, b, c, x, y; cin >> x >> y; b = c = a = y; int lol[4]; lol[0] = lol[1] = lol[2] = y; int k = 0; while (lol[0] != x || lol[1] != x || lol[2] != x) { sort(lol, lol + 3); lol[0] = min(lol[2] + lol[1] - 1, x); k++; } cout << k << endl; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
//package CF; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws Exception { Scanner bf = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int x = bf.nextInt(), y = bf.nextInt(); int [] a = {y,y,y}; int res = 0; while(!(a[0]==x && a[1] == x && a[2] == x)){ a[0] = Math.min(x, a[1]+a[2]-1); Arrays.sort(a); res++; } out.println(res); out.flush(); out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader fileReader) { br = new BufferedReader(fileReader); } 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 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
x,y = map(int,input().split()) if x//2<y: print(3) else: lis=[y]*3 c=0 while max(lis)<x: a=lis[1]+lis[2] lis.sort() lis[0]=a-1 lis.sort() # print(lis) c+=1 print(c+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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int[] a = {y,y,y}; int ans =0; while(a[0]<x || a[1]<x || a[2]<x) { a[0] = a[1]+a[2]-1; Arrays.sort(a); ans++; // System.out.println(a[0] + " " + a[1] + " " + a[2]); } System.out.println(ans); } 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CF712C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] givStr = br.readLine().split(" "); int x = Integer.parseInt(givStr[0]); int y = Integer.parseInt(givStr[1]); int turns = 0; int cura,curb,curc; cura=curb=curc=y; while(true) { if(cura>=x&&curb>=x&&curc>=x) break; turns++; if(turns%3==1) { cura = curb+curc-1; } if(turns%3==2) { curb = cura+curc-1; } if(turns%3==0) { curc = cura+curb-1; } //System.out.println(cura); //System.out.println(curb); //System.out.println(curc); } System.out.println(turns); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import sys def fastio(): from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() INF = 10**20 MOD = 10**9 + 7 I = lambda:list(map(int,input().split())) from math import gcd from math import ceil from collections import defaultdict as dd, Counter from bisect import bisect_left as bl, bisect_right as br r, l = I() a = [l, l, l] ans = 0 while a[-1] != r or a[0] != r: x = a[1] + a[2] a[0] = min(r, x - 1) 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class P1 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); int x = sc.nextInt(); int y = sc.nextInt(); int arr [] = {y , y , y}; int cnt = 0 ; while (arr[0] != x){ cnt ++ ; arr[0] = Math.min(x, arr[1] + arr[2] - 1); Arrays.sort(arr); } out.print(cnt); out.flush(); out.close(); } 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
#include <bits/stdc++.h> int x, y; int a[3]; int res; int main() { scanf("%d %d", &x, &y); res = 0; a[0] = a[1] = a[2] = y; while (1) { if (a[1] + a[2] - 1 >= x) { res += 3; break; } a[0] = a[1]; a[1] = a[2]; a[2] = a[0] + a[1] - 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
#include <bits/stdc++.h> using namespace std; int a, b, s, s1, m, n, y; int main() { cin >> a >> b; s = b; s1 = b; m += b * 3; while (s != a || s1 != a || a != b) { y++; n = min(min(s, b), s1); m -= n; if (n == b) { if (m - 1 <= a) b = m - 1, m += m - 1; else b = a, m += a; } else if (n == s) { if (m - 1 <= a) s = m - 1, m += m - 1; else s = a, m += a; } else if (n == s1) { if (m - 1 <= a) s1 = m - 1, m += m - 1; else s1 = a, m += a; } } cout << y << " "; return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int a[4], b, val1, val2, c, ans = 0; cin >> val1 >> val2; a[0] = a[1] = a[2] = val2; while (a[0] < val1 || a[1] < val1 || a[2] < val1) { sort(a, a + 3); a[0] = a[1] + a[2] - 1; ans++; } printf("%d\n", ans); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; import java.lang.*; import java.io.*; public class CodeforcesDiv2_370_Problem3 { public static void main(String[] args) { CodeforcesDiv2_370_Problem3 codeforces = new CodeforcesDiv2_370_Problem3(); Scanner scanner = new Scanner(System.in); int x = scanner.nextInt(); int y = scanner.nextInt(); int[] arr = new int[3]; for(int i=0; i<3; i++) arr[i] = y; System.out.println(codeforces.findCount(arr, x)); } public int findCount(int[] arr, int x) { int count = 0; while(matchCondition(arr, x)) { int highest = 0, second_highest = 0, lowest = 0; if(arr[0] >= arr[1] && arr[0] >= arr[2]) { highest = 0; if(arr[1] >= arr[2]) { second_highest = 1; lowest = 2; } else { second_highest = 2; lowest = 1; } } else if(arr[1] >= arr[0] && arr[1] >= arr[2]) { highest = 1; if(arr[0] >= arr[2]) { second_highest = 0; lowest = 2; } else { second_highest = 2; lowest = 0; } } else if(arr[2] >= arr[1] && arr[2] >= arr[0]) { highest = 2; if(arr[1] >= arr[0]) { second_highest = 1; lowest = 0; } else { second_highest = 0; lowest = 1; } } arr[lowest] = min(arr[second_highest]+arr[highest]-1, x); count++; printArr(arr); } return count; } public int min(int a, int b) { if(a<b) return a; return b; } public void printArr(int[] arr) { // System.out.println(arr[0] + " " + arr[1] + " " + arr[2]); } public boolean matchCondition(int[] arr, int y) { for(int i=0; i<3; i++) { if(arr[i]!=y) 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; inline void relax(long long& val, long long newval) { if (val == -1) { val = newval; } else { val = min(val, newval); } } void main1() { string s; getline(cin, s); map<char, int> count; for (auto c : s) { count[c]++; } int ans = abs(count['L'] - count['R']); ans += abs(count['D'] - count['U']); if (ans % 2 == 1) { cout << -1 << endl; } else { cout << ans / 2 << endl; } } int main() { int x, y; cin >> x >> y; int ans = 0; int a, b, c; a = b = c = y; while (a != x || b != x || c != x) { if (a != x) { ans++; } if (b != x) { ans++; } if (c != x) { ans++; } c = min(b + a - 1, x); b = min(a + c - 1, x); a = min(b + c - 1, x); } 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
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { // write your code here Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); int ans = 0; int a[] = {y,y,y}; while(a[0] < x) { a[0] = a[2]+a[1]-1; Arrays.sort(a); 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
a,b=map(int,input().split()) l=[b,b,b] k=0 while l[0]!=a or l[1]!=a or l[2]!=a : l[0]=min(a,l[2]+l[1]-1) l=sorted(l) 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
__author__ = 'choo-choo' x,y = map(int,raw_input().split()) def checktraingle(points): if(points[1]>points[2]): if(points[1]+points[2]-1 < x ): return [points[2],points[1],points[1]+points[2]-1] else: return [points[2],points[1],x] else : if(points[1]+points[2]-1 < x ): return [points[1],points[2],points[2]+points[1]-1] else: return [points[1],points[2],x] li=[y,y,y] count =0 while (li[0]!=x): count=count+1 li = checktraingle(li) print count
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int x = scanner.nextInt(); int y = scanner.nextInt(); // from x --> y int a, b, c; a = b = c = y; int remainLength = 3 * x - 3 * y; int ans = 0; while (remainLength > 0) { int m = findMin(a, b, c); int tar = a + b + c - m - m - 1; if (a == m) { if (a + tar > x) { tar = x - a; } a += tar; } else if (b == m) { if (b + tar > x) { tar = x - b; } b += tar; } else { if (c + tar > x) { tar = x - c; } c += tar; } remainLength -= tar; // System.out.println("(" + a + ", " + b + ", " + c + ") - " + // remainLength); ans++; } System.out.println(ans); scanner.close(); } static int findMin(int a, int b, int c) { return Math.min(Math.min(a, b), c); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int x, y; string s; bool isEquilateral(int t[], int x) { return t[0] == x && t[1] == x && t[2] == x; } int main() { cin >> x >> y; int t[3]; int steps; t[0] = y; t[1] = y; t[2] = y; steps = 0; while (true) { sort(t, t + 3); if (t[0] == x && t[2] == x) break; t[0] = min(t[2] + t[1] - 1, x); steps++; } printf("%d", steps); }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; import java.io.*; public class codeforces { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int x = in.nextInt(); int y = in.nextInt(); int a = y, b = y, c = y, max, min, ans = 0; while(a != x || b != x || c != x) { min = Math.min(a, Math.min(b, c)); max = Math.max(a, Math.max(b, c)); b = a+b+c - (max+min); a = min; c = max; a = Math.min(b+c-1, x); ans++; //pw.println(a+" "+b+" "+c); } pw.print(ans); pw.flush(); pw.close(); } public static HashMap<Long, Integer> primeFactorization(long n) { HashMap<Long, Integer> map = new HashMap<>(); for(long i=2;i*i<=n;i++) { while(n%i==0) { if(!map.containsKey(i)) map.put(i, 1); else map.put(i, map.get(i)+1); n/=i; } } if(n!=1) { if(!map.containsKey(n)) map.put(n, 1); else map.put(n, map.get(n)+1); } return map; } public static int BinarySearch_l(long[] a, long k) { int n = a.length; int i = 0, j = n-1; int mid = 0; if(k - a[n-1] > 0) return n; else { while(j - i > 0) { mid = (i+j)/2; if(k - a[mid] > 0) i = mid + 1; else j = mid; } } return i; } public static int BinarySearch_r(long[] a, long k) { int n = a.length; int i = 0, j = n-1; int mid = 0; if(k - a[0] < 0) return -1; else { while(j - i > 0) { mid = (int)Math.ceil((double)(i+j)/2); if(k - a[mid] >= 0) i = mid; else j = mid - 1; } } return i; } public static long fact(long n, long M) { long ans = 1; for(long i=n;i>0;i--) { ans = (ans*i)%M; } return ans; } /* public static void DFS(int sourse) { int count = 0; visited[sourse] = true; for(int u : adj[sourse]) { if(!visited[u]) { DFS(u); } } }*/ public static ArrayList Divisors(int n) { ArrayList<Integer> div = new ArrayList<>(); for (int i=1; i<=Math.sqrt(n); i++) { if (n%i == 0) { div.add(i); if(n/i != i) div.add(n/i); } } return div; } public static long GCD(long a,long b) { if(b==0) return a; else return GCD(b,a%b); } public static long LCM(long a,long b) { return (a*b)/GCD(a, b); } static class pair implements Comparable<pair> { Integer x, y; pair(int x,int y) { this.x=x; this.y=y; } public int compareTo(pair o) { int result = x.compareTo(o.x); if(result==0) result = y.compareTo(o.y); return result; } public String toString() { return x+" "+y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair)o; return p.x - x == 0 && p.y - y == 0 ; } return false; } public int hashCode() { return new Long(x).hashCode()*31 + new Long(y).hashCode(); } } 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); } } static class CodeX { public static void sort(long arr[]) { merge_sort(arr, 0, arr.length - 1); } private static void merge_sort(long A[], long start, long end) { if (start < end) { long mid = (start + end) / 2; merge_sort(A, start, mid); merge_sort(A, mid + 1, end); merge(A, start, mid, end); } } private static void merge(long A[], long start,long mid, long end) { long p = start, q = mid + 1; long Arr[] = new long[(int)(end - start + 1)]; long k = 0; for (int i = (int)start; i <= end; i++) { if (p > mid) Arr[(int)k++] = A[(int)q++]; else if (q > end) Arr[(int)k++] = A[(int)p++]; else if (A[(int)p] < A[(int)q]) Arr[(int)k++] = A[(int)p++]; else Arr[(int)k++] = A[(int)q++]; } for (int i = 0; i < k; i++) { A[(int)start++] = Arr[i]; } } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { #pragma warning(disable : 4996) int x, y, a, b, c, ans = 0; scanf("%d%d", &x, &y); int ar[3] = {y, y, y}; while (ar[0] != x || ar[1] != x || ar[2] != x) { ar[0] = min(x, ar[1] + ar[2] - 1); sort(ar, ar + 3); ans++; } printf("%d", ans); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class div2_370C { public static void main(String[] args) { @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); long x = sc.nextLong(); long y = sc.nextLong(); int laps = 0; long[] arr = {y,y,0}; for(;;){ if(x>arr[1]){ arr[2]=arr[0]+arr[1]-1; arr[0]=arr[1]; arr[1]=arr[2]; laps = laps+1; }else if(x<=arr[1]){ System.out.println((laps+2)); break; } } } }
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 MXN = (int)1e5 + 7; int a[3]; int main(void) { int x, y; scanf("%d %d", &x, &y); int ans = 0; for (int i = 0; i < 3; i++) a[i] = y; while (a[0] != x) { a[0] = min(x, a[2] + a[1] - 1); sort(a, a + 3); ans++; } printf("%d\n", ans); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
s, t = map(int, input().split()) s = [s, s, s] t = [t, t, t] it = 0 i = 0 while s[i] != t[i]: t[i] = min(s[i], t[(i+1)%3] + t[(i+2)%3] - 1) it += 1 i = (i+1)%3 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
import java.util.Arrays; import java.util.Collections; import java.util.PriorityQueue; import java.util.Scanner; /** * * @author DeLL */ public class Triangle { public static void main(String args[]){ Scanner in= new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); int[] arr= new int[3]; arr[0]=m; arr[1]=m; arr[2]=m; int min=0; while(true){ Arrays.sort(arr); if(arr[0]==n) break; if(arr[1]+arr[2]-1<=n) arr[0]=arr[1]+arr[2]-1; else arr[0]=n; min++; } System.out.println(min); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.*; public class Problem0712c { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int y = sc.nextInt(); int x = sc.nextInt(); int side1 = x; int side2 = x; int side3 = x; int time = 0; while(Math.max(Math.max(side1, side2), side3) < y) { side3 = (side1 + side2) - 1; time++; if (side3 >= y) { break; } side2 = (side1 + side3) - 1; time++; if(side2 >= y) { break; } side1 = (side2 + side3) - 1; time++; if(side1 >= y) { break; } } System.out.println(time+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()) v=[y]*3 t=0 while v[0]<x: v[0]=min(x,v[1]+v[2]-1) v.sort() t+=1 print t
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.*; public class C{ public static void func(int x,int y){ int arr[]={y,y,y}; int i=0; int count=0; int sum=y+y; while(true){ if(sum-1<=x){ arr[i]= sum-1; i++; //System.out.println("hi"); if(i==3){ i=0; } } else{ arr[i]=x; i++; // System.out.println("hee"); if(i==3){ i=0; } } count++; //System.out.println(count); sum=arr[0]+arr[1]+arr[2]-Math.min(arr[0],Math.min(arr[1],arr[2])); if(arr[0]==x || arr[1]==x || arr[2]==x){ //System.out.println(count); break; } } System.out.println(count+2); } public static void main(String args[]){ Scanner manik=new Scanner(System.in); int x=manik.nextInt(); int y=manik.nextInt(); func(x,y); } }
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(' ')) ans=0 A=[y]*3 while(sum(A)<x*3): A.sort() A[0]=min(x,A[1]+A[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 = 1e5 + 5; int a[3], x, y, cnt; bool judge() { for (int i = 0; i < 3; ++i) if (a[i] != x) return false; return true; } int main() { scanf("%d%d", &x, &y); a[0] = a[1] = a[2] = y; while (!judge()) { ++cnt; sort(a, a + 3); a[0] = min(x, a[1] + a[2] - 1); } printf("%d\n", cnt); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
goal, init = [int(n) for n in raw_input().split(' ')] a = b = c = init count = 0 while a < goal or b < goal or c < goal: a, b, c = sorted((a, b, c)) a = min(b + c - 1, goal) count += 1 print count
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; 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 holi; 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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int x, y; cin >> x >> y; int a, b, c, t = 0; a = b = c = y; while (1) { if (a >= x and b >= x and c >= x) { cout << t; return 0; } if (t % 3 == 0) a = b + c - 1; else if (t % 3 == 1) b = a + c - 1; else c = a + b - 1; ++t; } }
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 mod = 1e9 + 7; const long long inf = 3e18 + 5; int add(int a, int b) { return (a += b) < mod ? a : a - mod; } int mul(int a, int b) { return 1LL * a * b % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int x, y; cin >> x >> y; int a[3] = {y, y, y}; int res = 0; while (1) { if (a[0] == x && a[1] == x && a[2] == x) break; sort(a, a + 3); a[0] = min(x, a[1] + a[2] - 1); res++; } cout << res; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int a[3]; for (int i = 0, _b = (2); i <= _b; i++) a[i] = y; int res = 0; while (a[0] < x) { a[0] = min(a[1] + a[2] - 1, x); res++; sort(a, a + 3); } cout << res; }
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.math.*; import java.io.*; import java.text.DecimalFormat; import java.math.BigInteger; public class Main{ //static int d=20; static long mod=1000000007 ; //static HashMap<String,Integer> hm=new HashMap<>(); static ArrayList<ArrayList<Integer>> arr,arr2; static int size; //static int[] vis; public static void main(String[] args) throws IOException { boolean online =false; String fileName = "C-large"; PrintWriter out; if (online) { s.init(new FileInputStream(new File(fileName + ".in"))); out= new PrintWriter(new FileWriter(fileName + "out.txt")); } else { s.init(System.in); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } int x,y; x=s.ni(); y=s.ni(); int ans=0; int[] a=new int[3]; a[0]=a[1]=a[2]=y; while(a[0]!=x){ //System.out.println(a[0]+" "+a[1]+" "+a[2]); int l=a[0]+1; int h=x; while(l<h){ //System.out.println(l+" "+h); int mid=(l+h+1)/2; if((a[1]+a[2]>mid)&&(a[1]+mid>a[2])&&(a[2]+mid>a[1])){ l=mid; } else h=mid-1; } a[0]=(l+h+1)/2; ans++; Arrays.sort(a); } out.println(ans); out.close(); } public static long pow(long x,long y){ long ans=1; while(y>0){ if(y%2==1) ans=(ans*x); x=(x*x); y/=2; } return ans; } static class name implements Comparable<name> { String a; int num; public name(String x,int y){ a=x; num=y; } public int compareTo(name o){ if (num!=o.num){ return o.num-num; } else return a.compareTo(o.a); } } public static class s { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String ns() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static int ni() throws IOException { return Integer.parseInt( ns() ); } static double nd() throws IOException { return Double.parseDouble( ns() ); } static long nl() throws IOException { return Long.parseLong( ns() ); } } }
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 MODA = 1000003; inline void print(char pt) { printf("%c\n", pt); } inline void print(int pt) { printf("%d\n", pt); } inline void print(long long pt) { printf("%I64d\n", pt); } inline void print(double pt) { printf("%.20f\n", pt); } inline void print(char pt[]) { printf("%s\n", pt); } inline void print() { printf("\n"); } inline void scan(int &pt) { scanf("%d", &pt); } inline void scan(char &pt) { scanf("%c", &pt); } inline void scan(long long &pt) { scanf("%I64d", &pt); } inline void scan(double &pt) { scanf("%lf", &pt); } inline void scan(char pt[]) { scanf("%s", pt); } long long qpow(long long x, long long y) { x %= MODA; long long res = 1; while (y) { if (y % 2 == 1) { res *= x; res %= MODA; } x = x * x; x %= MODA; y /= 2; } return res; } long long extend_gcd(long long a, long long b, long long &x, long long &y) { if (a == 0 && b == 0) return -1; if (b == 0) { x = 1; y = 0; return a; } long long d = extend_gcd(b, a % b, y, x); y -= a / b * x; return d; } long long mod_reverse(long long a, long long MOD) { long long x, y; long long d = extend_gcd(a, MOD, x, y); if (d == 1) return (x % MOD + MOD) % MOD; else return -1; } void fail() { print("-1"); exit(0); } int x, y; int n; char stra[100008]; int a[10]; int main() { scan(x); scan(y); a[0] = y; a[1] = y; a[2] = y; for (int i = 1;; i++) { a[0] = a[1] + a[2] - 1; sort(a, a + 3); if (a[0] >= x) { print(i); return 0; } } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int t[3], temp = 0, i = 0, prod = b - 1, count = 0; t[0] = t[1] = t[2] = b; while (temp < 3) { if (t[i] >= a) { temp++; } else { t[i] = t[(i + 1) % 3] + t[(i + 2) % 3] - 1; count++; } i = (i + 1) % 3; } cout << count << "\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
x, y = map(int, input().split()) a = [y, y, y] count = 0 while not all(map(lambda _: _ == x, a)): a[0] = min(a[1] + a[2] - 1, x) a.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
import java.util.Scanner; import java.util.Arrays; public class Main { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); while (sc.hasNextInt()) { int x; x = sc.nextInt(); int y; y = sc.nextInt(); int[] N = { y, y, y }; int time = 0; while (N[0] != x) { if ((N[0] + N[1]) > x) { N[0] = x; time++; } else { N[0] = N[1] + N[2] - 1; time++; } Arrays.sort(N); } 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.util.Arrays; import java.util.Scanner; public class p712C { public static void main( String[] args ) { Scanner s = new Scanner( System.in ); int y = s.nextInt(), x = s.nextInt(); s.close(); int[] sides = { x, x, x }; int curSide = 0; int seconds = 0; while ( sides[ 0 ] != y || sides[ 1 ] != y || sides[ 2 ] != y ) { if ( sides[ curSide ] == y ) { curSide = ( curSide + 1 ) % 3; continue; } int a = sides[ ( curSide + 1 ) % 3 ], b = sides[ ( curSide + 2 ) % 3 ]; int nonDegenLen = a + b - 1; sides[ curSide ] = Math.min( nonDegenLen, y ); curSide = ( curSide + 1 ) % 3; seconds++; } System.out.println( seconds++ ); } }
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 y, x, a[3]; int main() { while (cin >> y >> x) { a[0] = a[1] = a[2] = x; int cnt = 0; while (a[0] < y || a[1] < y || a[2] < y) { sort(a, a + 3); a[0] = a[1] + a[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
#include <bits/stdc++.h> using namespace std; int x, y, a, b, c, cnt; void s() { if (a > b) swap(a, b); if (a > c) swap(a, c); if (b > c) swap(b, c); } int main(void) { scanf("%d%d", &x, &y); if (x > y) swap(x, y); a = x, b = x, c = x; while (a != y) { cnt++; a = min((b + c) - 1, y); s(); } 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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.IOException; import java.io.Reader; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Star Orpheus */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, FastScanner in, PrintWriter out) { int x = in.nextInt(), y = in.nextInt(); Integer[] a = new Integer[3]; x ^= y; y ^= x; x ^= y; int k = 0; Arrays.fill(a, x); while (true) { Arrays.sort(a); if (a[0] == y) break; k++; a[0] = Math.min(a[1] + a[2] - 1, y); } out.print(k); } } static class FastScanner { final static int BUFFER_SIZE = 65536; BufferedReader br; char[] buf = new char[BUFFER_SIZE]; int len = 0; int it = 0; boolean end = false; boolean delim(char c) { return c == ' ' || c == '\n' || c == '\r'; } void fillBuffer() { try { len = br.read(buf); } catch (IOException e) { e.printStackTrace(); } } void ensureBuffer() { if (it == len) { it = 0; fillBuffer(); if (len == -1) end = true; } } void moveNext() { while (!end) { ensureBuffer(); if (!delim(buf[it])) return; while (it < len && delim(buf[it])) it++; } } public int nextInt() { moveNext(); if (buf[it] == '-') { it++; return -nextInt(); } if (buf[it] == '+') { it++; return nextInt(); } int result = 0; while (!end) { int l = it; while (it < len && !delim(buf[it])) { result = (result * 10) + buf[it] - '0'; it++; } ensureBuffer(); if (end || delim(buf[it])) break; } return result; } public FastScanner(String file) { try { br = new BufferedReader(new FileReader(file), BUFFER_SIZE); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is), BUFFER_SIZE); } } }
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
/* * Code Author: Akshay Miterani * DA-IICT */ import java.io.*; import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.*; public class MainY { static double eps=(double)1e-6; static long mod=(int)1e9+6; public static void main(String args[]){ InputReader in = new InputReader(System.in); OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); //----------My Code---------- int x=in.nextInt(); int y=in.nextInt(); int a[]=new int[3]; a[0]=y;a[1]=y;a[2]=y; int count=0; while(a[0]!=x || a[1]!=x || a[2]!=x){ //debug(a); Arrays.sort(a); int target=a[2]+a[1]-1; if(target>x) target=x; a[0]=target; count++; } System.out.println(count); out.close(); //---------------The End------------------ } static long modulo(long a,long b,long c) { long x=1; long y=a; while(b > 0){ if(b%2 == 1){ x=(x*y)%c; } y = (y*y)%c; // squaring the base b /= 2; } return x%c; } public static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } static class Pair implements Comparable<Pair>{ int x; int y; int i; Pair(int xx,int yy){ x=xx; y=yy; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream inputstream) { reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine(){ String fullLine=null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine=reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int x, y; int a[4]; int main() { scanf("%d%d", &x, &y); a[1] = a[2] = a[3] = y; int ans = 0; while (a[1] != x || a[2] != x || a[3] != x) { ans++; int id = 1, sum = a[1]; for (int i = 2; i <= 3; i++) { if (a[i] < a[id]) id = i; sum += a[i]; } a[id] = min(sum - a[id] - 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 x, y, a[3], cnt = 0; int main() { scanf("%d%d", &x, &y); a[0] = a[1] = a[2] = y; while (1) { sort(a, a + 3); if (a[0] == x) break; cnt++; a[0] = min(x, a[1] + a[2] - 1); } printf("%d\n", cnt); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.util.Scanner; public class P712C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(), y = scan.nextInt(); int[] len = new int[3]; int sec = 0, last = -1; len[0]=len[1]=len[2] = y; while (last != sec) { last = sec; for (int i = 0; i < 3; i++) { if (len[i] == x) continue; int other = len[0]+len[1]+len[2] - len[i]; len[i] = Math.min(x, other-1); sec++; } } System.out.println(sec); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y=list(map(int,input().split())) a=[y,y,y] c=0 while 1>0: if x<=(a[0]+a[1]-1): print(c+3) break else: a[-1]=a[0]+a[1]-1 c+=1 a.sort(reverse=True)
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 read() { int x = 0, f = 0; char ch = 0; while (!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return f ? -x : x; } void write(int x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); } int x, y, na, nb, nc; int tot, ans; int main() { x = read(), y = read(); na = nb = nc = y; while (na < x || nb < x || nc < x) { tot++; ans++; if (tot == 1) na = nb + nc - 1; if (tot == 2) nb = na + nc - 1; if (tot == 3) nc = na + nb - 1, tot = 0; } write(ans); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.PriorityQueue; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class codeforces { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(bf.readLine()); int s = Integer.parseInt(st.nextToken()); int e = Integer.parseInt(st.nextToken()); int arr[] = new int[3]; arr[0] = arr[1] = arr[2] = e; int count = 0; while (arr[0] != s || arr[1] != s|| arr[2] != s) { Arrays.sort(arr); arr[0] = Math.min(arr[1] + arr[2] - 1, s); count++; } out.print(count); out.flush(); 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.util.*; import java.lang.*; import java.math.*; public class CF712C { public static void main(String args[]) { Scanner s = new Scanner(System.in); int x = s.nextInt(); int y = s.nextInt(); int res = devolve(x, y); System.out.println(res); } public static int devolve(int x, int y) { int res = 0; int a = y; int b = y; int c = y; int i = 0; // All must Increment up to x while (a != x || b != x || c != x) { // Vouga conditions //a + b > c if (i == 0) { c = Math.min(a + b - 1, x); } // b + c > a if (i == 1) { a = Math.min(b + c - 1, x); } // c + a > b if (i == 2) { b = Math.min(c + a - 1, x); } res++; i++; i = i % 3; //System.out.printf("%d, %d, %d \n", a, b, c); } return res; } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
y, x = map(int, raw_input().split()) t = [x, x, x] step_count = 0 while not all(i == y for i in t): t.sort() t[0] = min(y, t[2] + t[1] - 1) step_count += 1 print step_count
PYTHON
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
/** * Created by abhishek on 8/4/2016. */ import java.util.*; import java.io.*; public class Main { static int ans = 0; static void dfs(int array[],int x) { if (array[0] == x) return; int temp = Math.min(array[1] + array[2] - 1, x); array[0] = array[1]; array[1] = array[2]; array[2] = temp; ++ans; dfs(array, x); } public static void main(String[] args) throws Exception { 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 array[] = new int[3]; Arrays.fill(array,y); dfs(array,x); System.out.print(ans); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
x,y = map(int,input().split()) s = [y,y,y] k = 0 while sum(s)!=x*3: mi = min(s) ma = max(s) sr = sum(s)-ma-mi a = sum([sr,ma])-1 if a>x: a = x s[s.index(mi)] = 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.*; import java.io.*; public class Main { public static long mod= (long) (1e9 +7); public static void main(String args[]){ InputReader s= new InputReader(System.in); OutputStream outputStream= System.out; PrintWriter out= new PrintWriter(outputStream); int x= s.nextInt(); int y= s.nextInt(); int a=y,b=y,c=y; long turns=0; while(true){ if(a>=x && b>=x && c>=x){ out.println(turns); break; } turns++; if(turns%3==1){ a= b+c-1; } if(turns%3==2){ b=a+c-1; } if(turns%3==0){ c=a+b-1; } } out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream inputstream) { reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine(){ String fullLine=null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine=reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } } static class Pair implements Comparable<Pair> { long f,s; Pair(long ii, long cc) { f=ii; s=cc; } public int compareTo(Pair o) { return Long.compare(this.f, o.f); } } public static int gcd(int number1, int number2) { if(number2 == 0){ return number1; } return gcd(number2, number1%number2); } public static int combinations(int n,int r){ if(n==r) return 1; if(r==1) return n; if(r==0) return 1; return combinations(n-1,r)+ combinations(n-1,r-1); } public static long binomialCoeff(int n, int k) { long C[][]= new long[n+1][k+1]; int i, j; // Caculate value of Binomial Coefficient in bottom up manner for (i = 0; i <= n; i++) { for (j = 0; j <= Math.min(i, k); j++) { // Base Cases if (j == 0 || j == i) C[i][j] = 1; // Calculate value using previosly stored values else C[i][j] = C[i-1][j-1] + C[i-1][j]; } } return C[n][k]; } public static int expo(int a, int b){ if (b==1) return a; if (b==2) return a*a; if (b%2==0){ return expo(expo(a,b/2),2); } else{ return a*expo(expo(a,(b-1)/2),2); } } public static void sieve(int N){ int arr[]= new int[N+1]; for(int i=2;i<Math.sqrt(N);i++){ if(arr[i]==0){ for(int j= i*i;j<= N;j= j+i){ arr[j]=1; } } } // All the i for which arr[i]==0 are prime numbers. } }
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.*; public class Test { static int heaps = 0; public static void main(String args[]){ InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); long x = in.nextLong(); long y = in.nextLong(); long arr[] = new long[3]; long count = 0; arr[0] = arr[1] = arr[2] = y; while(arr[0]!=x||arr[1]!=x||arr[2]!=x){ Arrays.sort(arr); if( arr[1] +arr[2]>x) arr[0] = x; else arr[0] = arr[1] + arr[2] -1; count++; } out.println(count); out.close(); } private static long gcd(double lcm, long b){ while (b > 0) { long temp = b; b = (long) (lcm % b); // % is remainder lcm = temp; } return (long) lcm; } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int x = in.ni(), y = in.ni(), count = 0; int[] a = {y, y, y}; while (true) { if (a[0] == x) { out.println(count + 2); break; } Arrays.sort(a); a[0] = a[1] + a[2] - 1; if (a[0] > x) a[0] = x; count++; } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int ni() { 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
y, x = map(int, input(). split()) a = x; b = x; c = x; k = 0 while a < y or b < y or c < y: if a < c+b-1: a = c+b-1 k += 1 if a >= y and b >= y and c >= y: break if b < a+c-1: b = a+c-1 k += 1 if a >= y and b >= y and c >= y: break if c < a+b-1: c = a+b-1 k += 1 if a >= y and b >= y and c >= y: break 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 i, j, k, count = 0, n, a, b, a1[3], temp; cin >> a >> b; a1[0] = a1[1] = a1[2] = b; while (1) { if (a1[0] == a && a1[1] == a && a1[2] == a) break; sort(a1, a1 + 3); temp = a1[1] + a1[2] - 1; if (temp < a) a1[0] = temp; else a1[0] = a; count++; } cout << count; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2000010; int main() { vector<int> a(3); int x, y; while (cin >> x >> y) { for (int i = 0; i < 3; i++) { a[i] = y; } int res = 0; while (true) { sort(a.begin(), a.end()); if (a[0] == x) break; res++; a[0] = min(x, (a[1] + a[2] - 1)); } 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
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> y >> x; int a[3] = {x, x, x}; int ans = 0; while (a[0] < y) { a[0] = min(y, a[1] + a[2] - 1); sort(a, a + 3); ans++; } 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
def get_next(T): [a,b,c] = sorted(T) return [b,c,b+c-1] if __name__ == '__main__': y,x = [int(a) for a in input().split()] T = [x,x,x] # print(T) i = 0 while max(T) < y: T = get_next(T) # print(T) i+=1 print(2+i)
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.*; import java.io.*; public class Main { public static void main (String args[]) { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int x = in.nextInt(); int y = in.nextInt(); int arr[] = new int[3]; Arrays.fill(arr,y); int count=0; while(arr[0] !=x || arr[1] !=x || arr[2] !=x ) { int m = Math.min(arr[0], arr[1]); //System.out.println(m); int min = Math.min(m, arr[2]); //System.out.println(min); //count++; if(min == arr[0]) { if(arr[1]+arr[2] -1 <x) { arr[0] = arr[1]+arr[2] -1; } else { arr[0] =x; } count++; //System.out.println(arr[0]+" " +arr[1] +" " +arr[2]); continue; } else if(min == arr[1]) { if(arr[0]+arr[2] -1 <x) { arr[1] = arr[0]+arr[2] -1; } else { arr[1] =x; } count++; //System.out.println(arr[0]+" " +arr[1] +" " +arr[2]); continue; } else if(min==arr[2]) { if(arr[1]+arr[0] -1 <x) { arr[2] = arr[1]+arr[0] -1; } else { arr[2] =x; } count++; //System.out.println(arr[0]+" " +arr[1] +" " +arr[2]); continue; } } System.out.println(count); } } 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.util.Arrays; import java.util.Scanner; /** * Created by gobbles on 10.09.16. */ public class codeforce3 { private static Scanner is = new Scanner(System.in); public static void main(String[] args) { int real_len = is.nextInt(); int aim_len = is.nextInt(); int[] edges = new int[3]; edges[0] = edges[1] = edges[2] = aim_len; int time = 0; while (edges[0] < real_len) { edges[0] = Math.min(edges[1] + edges[2] - 1, real_len); Arrays.sort(edges); time++; } System.out.print(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
t, f = map(int, input().split()) s = [f] * 3 count = 0 while sum(s) < 3*t: s.sort() s[0] = min(t, s[1]+s[2] - 1) 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
x, a = map(int, input().split()) c = b = a i = 0 while a < x: [a,b,c] = sorted([b,c,c+b-1]) i+=1 print(i)
PYTHON3
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y, count = 0; cin >> x >> y; int a[3], i = 0; for (int i = 0; i < 3; i++) a[i] = y; while (a[0] != x || a[1] != x || a[2] != x) { count++; if (i == 0) { a[i] = min(x, a[1] + a[2] - 1); i++; } else if (i == 1) { a[i] = min(x, a[0] + a[2] - 1); i++; } else { a[i] = min(x, a[1] + a[0] - 1); i = 0; } } cout << count; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
read=input() read=read.split(" ") a=[0]*4 n=int(read[0]) m=int(read[1]) a[1]=m a[2]=m a[3]=m def mysort(): for i in range(1,4): for j in range(i,4): if a[i]>a[j]: a[i],a[j]=a[j],a[i] return def getans(): t=0 if n==m: return 0 while 0==0: mysort(); t=t+1; if a[2]+a[3]-1<=n : a[1]=a[2]+a[3]-1 else: a[1]=n if a[1]==n and a[2]==n and a[3]==n: return t return 0; print(getans())
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 C { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt() + 1; int y = scan.nextInt(); int[] sides = new int[3]; int ans = 0; Arrays.fill(sides, y); while (true) { Arrays.sort(sides); sides[0] = Math.min(sides[1] + sides[2] - 1, x); ans++; if (sides[0] == x) { ans += 2; break; } } System.out.println(ans); scan.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
n,k=map(int,input().split()) x=k y=k z=k turns=0 while True: if x>=n and y>=n and z>=n: print(turns) break turns+=1 if turns%3==1: x=y+z-1 if turns%3==2: y=z+x-1 if turns%3==0: z=x+y-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; const long long INF = 1000000000 + 7; const double esp = 1e-13; const long double PI = acos(-1.0); long long nhan(long long x, long long y, long long m) { long long ans = 0; while (y) { if (y % 2) ans = (ans + x) % m; x = x * 2 % m; y /= 2; } return ans; } long long power(long long a, long long n, long long m) { unsigned long long ans = 1; while (n) { if (n % 2) ans = ans * a % m; a = a * a % m; n /= 2; } return ans; } bool isPrime(long long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; long long p[3] = {3, 5, 7}; long long a, d; int r, s; d = n - 1; s = 0; while (d % 2 == 0) { d /= 2; s++; } for (long long i = 0; i <= 2; i++) { if (n == p[i]) return true; if (n % p[i] == 0) return false; a = power(p[i], d, n); if (a != 1) { for (r = 0; r < s && a != n - 1; r++) a = a * a % n; if (r == s) return false; } } return true; } long long phi(long long n) { long long ans = n; long long n2 = (long long)sqrt(n); for (long long i = 2; i <= n2; i++) if (n % i == 0) { while (n % i == 0) n /= i; ans -= ans / i; } if (n > 1) ans -= ans / n; return ans; } vector<int> readData(string str) { vector<int> vec; stringstream ss; int num; ss << str; while (ss >> num) vec.push_back(num); return vec; } string convert(string n, int sink, int des) { long long so = 0; string ans = ""; for (long long i = 0; i < n.length(); i++) { long long vt; if (n[i] <= '9') vt = n[i] - '0'; else vt = n[i] + 10 - 'A'; so = so * sink + vt; } while (so > 0) { long long vt = so % des; if (vt < 10) ans = (char)(vt + 48) + ans; else ans = char(vt + 'A' - 10) + ans; so /= des; } return ans; } void makeTest() { srand(time(0)); } int x, y, a, b, cur, ans; int main() { ios_base::sync_with_stdio(false); cin.tie(); cin >> x >> y; a = y; b = y; ans = 2; while (cur < x) { cur = a + b - 1; a = b; b = cur; 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
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y; cin >> x >> y; long long int a, b, c; a = y; b = y; c = y; long long int count = 0; while (1) { if (a >= x && b >= x && c >= x) { cout << count << endl; break; } count++; if (count % 3 == 1) { a = b + c - 1; } if (count % 3 == 2) { b = a + c - 1; } if (count % 3 == 0) { c = a + b - 1; } } }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.InputMismatchException; import java.util.Scanner; public class Main { static FasterScanner sc; //static ArrayList<Integer>[] arr; //static boolean[] b; public static void main(String args[] ) throws Exception { FasterScanner sc= new FasterScanner(); int y = sc.nextInt(), x = sc.nextInt(); int arr[] = new int[3]; arr[0] = x; arr[1] =x;arr[2] = x; int cnt = 0; if(x==y) System.out.println("0"); else{ while(true){ if(arr[0]>=y && arr[1]>=y && arr[2]>=y) break; arr[0] = arr[1] + arr[2]-1; cnt++; if(arr[0]>=y && arr[1]>=y && arr[2]>=y) break; arr[1] = arr[2] + arr[0] -1; cnt++; if(arr[0]>=y && arr[1]>=y && arr[2]>=y) break; arr[2] = arr[1] + arr[0] - 1; cnt++; } System.out.println(cnt); } } public static int min(int a,int b, int c){ if(a<b){ if(c<a) return c; return a; } else{ if(c<b) return c; return b; } } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int a[3]; int main() { ios::sync_with_stdio(0); cin.tie(0); int x, y; cin >> x >> y; a[0] = a[1] = a[2] = y; int m = 0; while (a[0] + a[1] + a[2] != 3 * x) { sort(a, a + 3); ++m; a[0] = min(x, a[1] + a[2] - 1); } cout << m << "\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 x, y, ans; int a[3]; inline void ssort() { if (a[0] > a[1]) swap(a[0], a[1]); if (a[0] > a[2]) swap(a[0], a[2]); if (a[1] > a[2]) swap(a[1], a[2]); } inline int solve() { a[0] = a[1] = a[2] = y; int ans = 0; while (!(a[0] == a[1] && a[1] == a[2] && a[0] == x)) { ssort(); a[0] = a[1] + a[2] - 1 > x ? x : a[1] + a[2] - 1; ans++; } return ans; } int main() { while (~scanf("%d%d", &x, &y)) { printf("%d\n", solve()); } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; vector<int> v; int main() { int x, y; cin >> x >> y; for (int i = 0; i < 3; i++) v.push_back(y); int ans = 0; while (true) { sort(v.begin(), v.end()); if (v[0] == v[2] && v[0] == x) break; v[0] = v[1] + v[2] - 1; if (v[0] > x) v[0] = x; ans++; } 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
#!/usr/bin/env python x, y = (int(i) for i in raw_input().split()) if x > y: x, y = (y, x) a, b, c = (x, x, x) i = 0 while a != y or b != y or c != y: a = min(b + c - 1, y) new_a = min(a, b, c) new_c = max(a, b, c) a, b, c = (new_a, a + b + c - new_a - new_c, new_c) i += 1 print i
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
line = raw_input().split(" ") a, b = int(line[0]), int(line[1]) x, y, z = b, b, b steps = 0 while True: if z == a: break steps += 1 z = min(a, x-1+y) x, y, z = z, x, y print steps
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.Arrays; import java.util.Scanner; public class C { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); int x = s.nextInt(), y = s.nextInt(); int[] arr = {y,y,y}; int cnt = 0; while (true) { Arrays.sort(arr); if (arr[0] == x) break; arr[0] = Math.min(x, arr[1]+arr[2]-1); cnt++; } System.out.println(cnt); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 10; const int MAXN = 1e4 + 10; const int MOD = 1e9 + 7; const int inf = 1e9; const double pi = acos(-1.0); const double eps = 1e-6; int dx[] = {0, -1, 0, 1}; int dy[] = {1, 0, -1, 0}; int x, y; int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> x >> y; a = b = c = y; int res = 0; while (a < x || b < x || c < x) { int maxa = max(a, max(b, c)); int maxc = min(a, min(b, c)); int maxb = a + b + c - maxa - maxc; int l = maxa + maxb - maxc - 1; if (a == maxc) a += l; else if (b == maxc) b += l; else c += l; res++; } cout << 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
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; int cnt = 0; int a = y, b = y, c = y; while (a != x || b != x || c != x) { if (a != x) { a = min((b + c - 1), x); cnt++; } if (b != x) { b = min((a + c - 1), x); cnt++; } if (c != x) { c = min((a + b - 1), x); cnt++; } } 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
//package pkg712c; import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { int x, y, count = 0; int[] num = new int[3]; Scanner scan = new Scanner(System.in); x = scan.nextInt(); y = scan.nextInt(); for (int i = 0; i < 3; i++) { num[i] = y; } while (true) { Arrays.sort(num); if (num[1] + num[2] > x) { num[0] = x; } else { num[0] = num[1] + num[2] - 1; } count++; if (num[0] == num[1] && num[1] == num[2] && num[2] == x) { break; } } System.out.println(count); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int num[1 << 18]; char str[20]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int x, y; cin >> x >> y; int a, b, c, ans = 0; a = b = c = y; while (a < x) { swap(a, b); swap(b, c); c = a + b - 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.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class G { public static void main(String[] args) throws NumberFormatException, IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int x = sc.nextInt(), y = sc.nextInt(); int[] a = { y, y, y }; int ans = 0; while(a[0] != x) { ++ans; a[0] = Math.min(x, a[1] + a[2] - 1); Arrays.sort(a); } out.println(ans); out.flush(); out.close(); } static class Scanner { BufferedReader br; StringTokenizer st; Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s)); } String next() throws IOException { while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; int main() { int x, y; scanf("%d%d", &x, &y); int arr[3]; for (int i = 0; i < 3; i++) arr[i] = y; int cnt = 0; while (true) { int sum = arr[1] + arr[2]; if (sum - 1 >= x) arr[0] = x; else arr[0] = sum - 1; sort(arr, arr + 3); cnt++; if (arr[0] == x && arr[1] == x && arr[2] == x) break; } printf("%d", 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
y, x = map(int, input().split()) def f(a): a = sorted(a) if a[0] == y: return 0 a[0] = min(sum(a[1:]) - 1, y) return 1 + f(a) print(f([x, x, x]))
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 dx[]{1, -1, 0, 0, 1, -1, 1, -1}; int dy[]{0, 0, 1, -1, 1, -1, -1, 1}; long long suf(long long x) { return (x * (x + 1)) / 2; } vector<vector<pair<int, int> > > adj; const long long mod = 1e9 + 7, oo = 1e18; int n, m, x, y, z; int main() { string s; while (cin >> x >> y) { swap(x, y); int a = x, b = x, c = x, ans = 0; while (a < y || b < y || c < y) { if (a < b + c - 1 && a < y) ans++, a = b + c - 1; if (b < a + c - 1 && b < y) ans++, b = a + c - 1; if (c < a + b - 1 && c < y) ans++, c = a + b - 1; } cout << ans << endl; } return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Hieu Le */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); C solver = new C(); solver.solve(1, in, out); out.close(); } static class C { public void solve(int testNumber, InputReader in, PrintWriter out) { int x = in.nextInt(); int y = in.nextInt(); int[] length = {y, y, y}; int cnt = 0; while (!surpass(length, x)) { ++cnt; Arrays.sort(length); length[0] = length[1] + length[2] - 1; } out.println(cnt); } private boolean surpass(int[] length, int x) { for (int i = 0; i < length.length; ++i) { if (length[i] < x) return false; } return true; } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; private static final int BUFFER_SIZE = 32768; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; const int N = (int)1e5 + 10; const int inf = (int)1e9 + 10; int solve(int a, int b, int c, int A) { int mn = min(a, min(b, c)); if (mn == A) return 0; if (mn == a) return solve(min(b + c - 1, A), b, c, A) + 1; else if (mn == b) return solve(a, min(a + c - 1, A), c, A) + 1; else return solve(a, b, min(a + b - 1, A), A) + 1; } int main() { ios_base::sync_with_stdio(false); int a, b; cin >> a >> b; cout << solve(b, b, b, a); return 0; }
CPP
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
#include <bits/stdc++.h> using namespace std; long long a, b, sol, i, fi, se, th, temp; priority_queue<long long> Q; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> a >> b; sol = 0; for (i = 0; i < 3; i++) { Q.push(b); } while (true) { fi = Q.top(), Q.pop(); se = Q.top(), Q.pop(); th = Q.top(), Q.pop(); temp = min(fi + se - 1, a); if (temp == a) { sol += 3; break; } sol++; Q.push(temp), Q.push(fi), Q.push(se); } cout << sol << 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 a[4]; int x, y; bool check() { if (a[0] == x && a[1] == x && a[2] == x) return true; return false; } int main() { scanf("%d%d", &x, &y); a[0] = a[1] = a[2] = y; int res = 0; while (!check()) { res++; sort(a, a + 3); int minn = min(x, a[1] + a[2] - 1); a[0] = minn; } printf("%d", res); }
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.InputStreamReader; import java.util.StringTokenizer; public class C370 { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int start = Integer.parseInt(st.nextToken()); int end = Integer.parseInt(st.nextToken()); int a = end; int b = end; int c = end; int count = 0; while (!(a == start && b == start && c == start)) { count++; if (a <= b && a <= c) { a = Math.min(start, b + c - 1); } else if (b <= a && b <= c) { b = Math.min(start, a + c - 1); } else { c = Math.min(start, a + b - 1); } } System.out.println(count); } }
JAVA
712_C. Memory and De-Evolution
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y. In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer. What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y? Input The first and only line contains two integers x and y (3 ≀ y < x ≀ 100 000) β€” the starting and ending equilateral triangle side lengths respectively. Output Print a single integer β€” the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x. Examples Input 6 3 Output 4 Input 8 5 Output 3 Input 22 4 Output 6 Note In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>. In the second sample test, Memory can do <image>. In the third sample test, Memory can do: <image> <image>.
2
9
import java.io.*; import java.util.*; public class Main{ private static InputReader in = new InputReader(System.in); public static void main(String args[]) { int n = in.readInt(), m= in.readInt(); int a = m, b = m, c = m,op=0; while(a<n || b<n || c<n) { if(a<=b && a<=c) { a = Math.min(b+c-1,n); }else if(b<=c) { b = Math.min(a+c-1,n); }else c = Math.min(b+a-1, n); op++; } System.out.println(op); } } /*public class Main{ private static InputReader in = new InputReader(System.in); public static void main(String args[]) { int n =in.readInt(); long a[]=new long[n],b[]=new long[n]; for(int i=0;i<n;i++) { a[i]=(long)in.readInt(); } b[n-1]=a[n-1]; long sum=b[n-1]; for(int i=n-2;i>=0;i--) { b[i]=a[i]+sum; sum=b[i]-sum; } for(int i=0;i<n;i++) { System.out.println(b[i]); } } }*/ class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } }
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.Closeable; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class C { public static void main(String... args) throws Exception { FastScan sc = new FastScan(new BufferedReader(new InputStreamReader(System.in))); PrintWriter pw = new PrintWriter(System.out); int y = sc.in(); int x = sc.in(); int[] sides = new int[] { x, x, x }; int steps = 0; while (sides[steps++ % 3] < y) { sides[steps % 3] = sides[(steps + 1) % 3] + sides[(steps + 2) % 3] - 1; } pw.println(steps + 1); sc.close(); pw.close(); System.exit(0); } static class FastScan implements Closeable { private BufferedReader br; private StringTokenizer tk; public FastScan(BufferedReader br) { this.br = br; } public int in() throws NumberFormatException, IOException { return Integer.parseInt(next()); } public long ln() throws NumberFormatException, IOException { return Long.parseLong(next()); } public double db() throws NumberFormatException, IOException { return Double.parseDouble(next()); } @Override public void close() throws IOException { tk = null; br.close(); } public String next() throws IOException { while (tk == null || !tk.hasMoreTokens()) { String line = br.readLine(); if (line == null) return null; tk = new StringTokenizer(line); } return tk.nextToken(); } } }
JAVA