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.util.*;
public class Main {
public static void main(String[]args){
Scanner kb = new Scanner(System.in);
while(kb.hasNext()){
int n = kb.nextInt();
int m = kb.nextInt();
int a=m;//xiao
int b=m;//zhong
int c=m;//da
int d=0;
while(!(a==n&&b==n&&c==n)){
if(a>b){int t=a;a=b;b=t;}
if(b>c){int t=b;b=c;c=t;}
if(b+c>n){
a=n;
}else{
a=b+c-1;
}
d++;
}
System.out.println(d);
}
}
}
| 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 MX = -1;
int main() {
int a, b, c;
int p, k;
cin >> p >> k;
a = b = c = k;
int wyn = 0;
while (1) {
a = min(p, b + c - 1);
if (a > b) swap(a, b);
if (a > c) swap(a, c);
if (b > c) swap(b, c);
++wyn;
if (a == p && b == p && c == p) break;
}
cout << wyn;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void customrun() {}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool isprime(long long n) {
for (long long i = 2; (long long)i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
long long fib(int n) {
long long a = 0, b = 1, c, i;
if (n == 0) return a;
for (i = 2; i <= n; i++) {
c = (a + b);
a = b;
b = c;
}
return b;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long extendedgcd(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long x1, y1;
long long d = extendedgcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
long long findgrouplcm(vector<int> &arr, int n) {
long long ans = arr[0];
for (long long i = 1; i < n; i++) ans = (arr[i] * (ans / (gcd(arr[i], ans))));
return ans;
}
long long powerwithmod(long long x, unsigned long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
bool comp(const pair<long, long> &a, const pair<long, long> &b) {
if (a.first == b.first) return a.second < b.second;
return a.first < b.first;
}
void solve();
int main() {
clock_t begin = clock();
fast();
customrun();
long long t = 1;
for (long long i = (1); i < (t + 1); i += (1)) {
solve();
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
return 0;
}
void solve() {
int n, m;
cin >> n >> m;
int arr[3] = {m, m, m}, ans = 0;
while ((arr[0] != n) || (arr[1] != n) || (arr[2] != n)) {
sort(arr, arr + 3);
arr[0] = min(n, arr[1] + arr[2] - 1);
ans++;
}
cout << (ans);
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by MohannadHassanPersonal on 9/14/16.
*/
public class MemoryAndDeEvolution {
public static void main(String [] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
int start = Integer.parseInt(input[0]);
int target = Integer.parseInt(input[1]);
int a = target, b = target, c = target;
int turns = 0;
while (true) {
if (a >= start && b >= start && c >= start)
break;
if (turns % 3 == 0) {
a = b + c - 1;
}
else if (turns % 3 == 1) {
b = a + c - 1;
}
else {
c = a + b - 1;
}
turns++;
}
System.out.println(turns);
}
}
| JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | x, y = [int(x) for x in input().split(' ')]
triset = [y] * 3
c = 0
while sum(triset) < x*3:
triset.sort()
triset[0] = triset[2] + triset[1] - 1
if triset[0] > x: triset[0] = x
c += 1
print(c)
| 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;
int ar[3];
cin >> x >> y;
for (int i = 0; i < 3; i++) ar[i] = y;
while (ar[0] + ar[1] + ar[2] != 3 * x) {
ar[0] = min(x, ar[1] + ar[2] - 1);
sort(ar, ar + 3);
count++;
}
cout << count;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | a,b = raw_input().split()
a = int(a)
b = int(b)
if a == b:
print 0
exit()
c = 0
tri = [b,b,b]
while 1:
tri.sort()
maxx = tri.pop()
midd = tri.pop()
minn = tri.pop()
minn = midd + maxx - 1
if minn > a:
minn = a
tri = [minn, midd, maxx]
c += 1
if tri == [a,a,a]:
break
print c | PYTHON |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
static int i, j, k, n, m, t, y, x, sum = 0;
static long mod = 1000000007;
static FastScanner fs = new FastScanner();
static PrintWriter out = new PrintWriter(System.out);
static String str;
static long ans;
public static void main(String[] args) {
t = 1;
while (t-- > 0) {
n = fs.nextInt();
k = fs.nextInt();
int [] arr = new int[3];
arr[0] = k;
arr[1] = k;
arr[2] = k;
while(!isValid(arr)){
arr[0] = Math.min(n, arr[1]+arr[2]-1);
ruffleSort(arr);
ans++;
}
out.println(ans);
}
out.close();
}
static boolean isValid(int[] arr){
if(arr[0]== n && arr[1]==n && arr[2]==n)
return true;
return false;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static void ruffleSort(int[] a) {
//ruffle
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n), temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
//then sort
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
//ruffle
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
long temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
//then sort
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
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());
}
}
static class Pair implements Comparable<Pair> {
long first, second;
public Pair(long first, long second) {
this.first = first;
this.second = second;
}
@Override
public int compareTo(Pair o) {
return Long.compare(first, o.first);
}
}
} | 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 | //package cf712;
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.HashMap;
public class cf3 {
public static void main(String[] args){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
try {
String [] temp = br.readLine().split("\\s") ;
int x = Integer.parseInt(temp[0]) ;
int y = Integer.parseInt(temp[1]) ;
//int k = ret(x,y) ;
//ans += Math.max(0, compute3(x-y)*2) ;
int ans = 0 ;
int count = 0 ;
int[] side = {y,y,y} ;
while(count != 3){
if (side[1]+side[2]-1 > x){
side[0] = x ;
count++ ;
}else {
side[0] = side[1]+side[2]-1 ;
}
ans++ ;
Arrays.sort(side);
}
System.out.println(ans);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.util.Scanner;
import java.util.Arrays;
public class Main {
static int x, y;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
x = sc.nextInt(); y = sc.nextInt();
int sec = 0;
int[] tri = new int[]{y, y, y};
while(tri[0] != x || tri[1] != x || tri[2] != x){
Arrays.sort(tri);
tri[0] = Math.min(x, tri[1] + tri[2] - 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 | #include <bits/stdc++.h>
using namespace std;
struct cmp {
bool operator()(pair<int, int> a, pair<int, int> b) {
return a.second > b.second;
}
};
long long modpow(long long base, long long exp, long long mod) {
base %= mod;
long long result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return result;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long x, y, ans = 0;
cin >> x >> y;
if (y > (x - y)) {
ans = 3;
cout << ans << endl;
} else {
long long a, b, c;
a = y, b = y, c = y;
while (c < x) {
a = b + c - 1;
long long t = a;
a = b;
b = c;
c = t;
ans++;
}
cout << ans + 2 << endl;
}
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | x, y = map(int, input().split())
x, y = y, x
A = x
B = x
curr = x
count = 0
while curr < y:
curr = B + A - 1
A, B = B, curr
count += 1
count += 2
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 | from sys import stdin
n,m=map(int,stdin.readline().strip().split())
x=[m,m,m]
ans=0
while not (x[0]>=n and x[1]>=n and x[2]>=n):
ans+=1
x.sort()
y=x[1]+x[2]-1
x[0]=y
print(ans)
| PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.util.*;
/**
*
* @author arif_
* Algo: Greedy
* Level: Medium
*/
public class CF_taskC{
/* START OF I/O ROUTINE */
// PrintWriter for faster output
public static PrintWriter out;
// MyInputReader class for faster input
public static class MyInputReader {
BufferedReader br;
StringTokenizer st;
public MyInputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream), 32768);
}
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;
}
} // end of class MyInputReader
/* END OF I/O ROUTINE */
public static void main(String[] args) {
MyInputReader in = new MyInputReader(System.in);
out = new PrintWriter(new BufferedOutputStream(System.out));
int x = in.nextInt();
int y = in.nextInt();
int a[] = new int[3];
Arrays.fill(a, y);
int ans = 0;
while(true) {
Arrays.sort(a);
if(a[0] >= x) break;
a[0] = a[1] + a[2] - 1;
ans++;
}
out.println(ans);
out.close();
} // end of method main()
} // end of class Main | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | x, y = map(int, input().split())
a, b, c = y, y, y
ans = 0
while a < x:
a, b, c = b, c, b + c - 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
//sides: 22,22,22
//sides: 22,12,11
//sides: 4,12,11
//sides: 4,8,11
//sides: 4,8,5
//sides: 4,4,5
//sides: 4,4,4
//4 -> 22
//4,4,4
//5,5,5
//5,8,5
public class C {
public static int solve(int start, int end) {
if(start > end) {
int temp = start;
start = end;
end = temp;
}
int [] sides = {start,start,start};
int numSeconds = 0;
while(sides[0] != end || sides[1] != end || sides[2] != end) {
int nextPoint = sides[1] + sides[2] - 1;
nextPoint = Math.min(end, nextPoint);
sides[0] = nextPoint;
numSeconds++;
Arrays.sort(sides);
}
return numSeconds;
}
public static void main(String [] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer = new StringTokenizer(br.readLine());
int start = Integer.parseInt(tokenizer.nextToken());
int end = Integer.parseInt(tokenizer.nextToken());
System.out.println(solve(start,end));
}
}
| JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int x, y;
cin >> x >> y;
int testa = y, testb = y, testc = y;
int turns = 0;
while (true) {
if (testa >= x && testb >= x && testc >= x) {
cout << turns << endl;
return 0;
}
turns++;
if (turns % 3 == 0) {
testa = testb + testc - 1;
}
if (turns % 3 == 1) {
testb = testa + testc - 1;
}
if (turns % 3 == 2) {
testc = testb + testa - 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 | #include <bits/stdc++.h>
using namespace std;
struct node {
int x;
int y;
};
int main() {
int x[3], y[3];
int n, m;
while (~scanf("%d%d", &n, &m)) {
int cnt = 0;
x[0] = x[1] = x[2] = m;
while (1) {
sort(x, x + 3);
if (x[2] >= n) break;
x[0] = x[2] + x[1] - 1;
cnt++;
}
printf("%d\n", cnt + 2);
}
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | x, y = map(int, raw_input().split(' '))
t = [y, y, y]
goal = 3 * x
finish = False
cnt = 0
while not finish:
for i in range(3):
cnt += 1
t[i] = min(sum(t) - t[i] - 1, x)
if sum(t) == goal:
finish = True
break
print cnt | PYTHON |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.util.*;
public class C
{
public static void main(String[] args)
{
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int a = sc.nextInt(), b = sc.nextInt();
ArrayList<Integer> inp = new ArrayList<Integer>();
inp.add(b);
inp.add(b);
inp.add(b);
Collections.sort(inp);
int ans = 0;
while(true) {
//System.out.printf("%d %d %d %d\n", inp.get(0), inp.get(1), inp.get(2), a);
if( inp.get(0).equals(inp.get(1)) && inp.get(1).equals(inp.get(2)) && inp.get(0).equals(a) )
break;
ans++;
inp.remove(0);
inp.add(Math.min(inp.get(0) + inp.get(1) - 1, a));
Collections.sort(inp);
}
out.println(ans);
out.close();
}
// PrintWriter for faster output
public static PrintWriter out;
// MyScanner class for faster input
public static class MyScanner
{
BufferedReader br;
StringTokenizer st;
public MyScanner()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
boolean hasNext()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
return false;
}
}
return true;
}
String next()
{
if (hasNext())
return st.nextToken();
return null;
}
int nextInt()
{
return Integer.parseInt(next());
}
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 |
x, y = map(int, raw_input().split())
last = [y, y, y]
ans = 0
while last != [x, x, x]:
last.sort()
last[0] = min(x, last[1]+last[2]-1)
ans += 1
print ans
| PYTHON |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, need;
int k = 0;
cin >> a >> need;
if (a > need) swap(a, need);
b = a;
c = a;
while (!(a == need && b == need && c == need)) {
if (a <= b && a <= c) {
a = min(need, (b + c - 1));
} else if (b <= a && b <= c) {
b = min(need, (a + c - 1));
} else {
c = min(need, (b + a - 1));
}
k += 1;
}
cout << k;
}
| 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 increase_triangle_side(first_side, second_side, third_side, count_increas_times, ending_length):
count_increas_times += 1
if first_side > second_side:
first_side, second_side = second_side, first_side
if first_side > third_side:
first_side, third_side = third_side, first_side
first_side = second_side + third_side - 1
# print(first_side, second_side, third_side)
if first_side > ending_length and second_side > ending_length and third_side > ending_length:
return count_increas_times
else:
return increase_triangle_side(first_side, second_side, third_side, count_increas_times, ending_length)
def counting_changing_times():
x, y = map(int, input().split())
changing_times = increase_triangle_side(y, y, y, 0, x)
print(changing_times)
counting_changing_times()
| 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 | s,e = map(int,raw_input().split())
a = max(s,e)
b = min(s,e)
count = 0
prev = b
cur = b
while(cur < a):
cur,prev = cur+prev-1,cur
count += 1
print count+2
| 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 sys
fin = sys.stdin
# fin = open('tri.in', 'r')
while True:
s = fin.readline().strip()
if s == '':
break
x, y = [int(x) for x in s.split()]
a, b, c = y, y, y
time = 0
while a < x:
time += 1
a, b, c = b, c, b + c - 1
print(time)
| PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.text.Format;
import java.util.*;
public class Test {
static BufferedReader in = null;
static PrintWriter out = null;
static StringTokenizer st = new StringTokenizer("");
static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") == null;
public static void main(String[] args) {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
/*String filename = "dwarf";
if (ONLINE_JUDGE) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader(filename + ".in"));
out = new PrintWriter(filename + ".out");
}*/
solve();
out.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String readString() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(in.readLine(), " \n:.");
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public static int readInt() {
return Integer.parseInt(readString());
}
public static long readLong() {
return Long.parseLong(readString());
}
public static double readDouble() {
return Double.parseDouble(readString());
}
private static long binPow(long x, int step) {
if (step == 0) return 1;
if (step == 1) return x % mod;
if (step % 2 == 0) {
long temp = binPow(x, step / 2) % mod;
return (temp * temp) % mod;
}
return (x * binPow(x, step - 1)) % mod;
}
private static int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
private static int gcd(int x, int y) {
while (x > 0 && y > 0) {
if (x > y) x %= y;
else y %= x;
}
return x + y;
}
private static long mod = 1_000_000_007;
private static double EPS = 1e-6;
private static int MAX_N = (int) 1e6 + 1;
private static void solve() throws IOException {
int x = readInt();
int y = readInt();
out.print(kek(y, y, y, 0, x) + 2);
}
private static int kek(int a, int b, int c, int count, int y) {
while ((a != y)) {
c = Math.min(b + a - 1, y);
int max = Math.max(a, Math.max(b, c));
int min = Math.min(a, Math.min(b, c));
int average = a + b + c - max - min;
a = max;
b = average;
c = min;
count++;
}
return 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 | x,y=[int(x) for x in input().split()]
a,b,c=y,y,y
ans=0
while a<x and b<x and c<x:
mini=min(a,b,c)
if mini==a:
a=b+c-1
elif mini==b:
b=a+c-1
else:
c=a+b-1
ans+=1
print(ans+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 | def main():
x, s = map(int, raw_input().split())
s2 = s3 = s
ans = 0
while s < x:
ans += 1
s, s2, s3 = s2, s3, s2 + s3 - 1
print ans
if __name__ == '__main__':
main()
| PYTHON |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;
public class practice {
// heloo world nudniobv udivbo
// buyfhsfnoisdfnoi
public static void merge(int arr[], int l, int m, int r) {
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
int L[] = new int[n1];
int R[] = new int[n2];
/*Copy data to temp arrays*/
for (int i = 0; i < n1; ++i)
L[i] = arr[l + i];
for (int j = 0; j < n2; ++j)
R[j] = arr[m + 1 + j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
// Main function that sorts arr[l..r] using
// merge()
public static void sort(int arr[], int l, int r) {
if (l < r) {
// Find the middle point
int m = (l + r) / 2;
// Sort first and second halves
sort(arr, l, m);
sort(arr, m + 1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
public static long getValue(char a, char b, char x[]) {
long m1 = 0, m2 = 0, ans = 0;
for (int i = 0; i < x.length; i++) {
if (i % 2 == 0 && x[i] != a) {
m1++;
}
if (i % 2 != 0 && x[i] != b) {
m2++;
}
}
ans = Math.max(m1, m2);
return ans;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int a = y;
int b= y;
int c = y;
int ans = 0;
while(true){
//check the current
if(a>=x && b>=x && c>=x){
System.out.println(ans);
break;
}
ans++;
if(ans%3==1){
//update a
a = b+c-1;
}
if(ans%3==2){
//update b
b = a+c-1;
}
if(ans%3==0){
//update c
c = a+b-1;
}
}
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #import sys
n=map(int,raw_input().split())
n2=n[0]
n1=n[1]
if n1==n2:
print 0
else:
mn=99999999999
l=[n1,n1,n1]
step=0
ind=0
while 1==1:
#print l,step,ind
if l[0]>=n2 and l[1]>=n2 and l[2]>=n2:
break
step+=1
ind=step%3
if ind==1 :
#if l[ind]!=n2:
l[ind]=l[2]+l[0]-1
#step+=1
'''if l[0]>=l[1] and l[0]>=l[2]:
ind=0
if l[2]>=l[1] and l[2]>=l[0]:
ind=2
if l[1]>=l[0] and l[1]>=l[2]:
ind=1'''
#ind=2
elif ind==2 :
#if l[ind]!=n2:
l[ind]=l[1]+l[0]-1
#step+=1
'''if l[0]>=l[1] and l[0]>=l[2]:
ind=0
if l[2]>=l[1] and l[2]>=l[0]:
ind=2
if l[1]>=l[0] and l[1]>=l[2]:
ind=1'''
#ind=0
else:
#if l[ind]!=n2:
l[ind]=l[2]+l[1]-1
#step+=1
#ind=1
'''if l[0]>=l[1] and l[0]>=l[2]:
ind=0
if l[2]>=l[1] and l[2]>=l[0]:
ind=2
if l[1]>=l[0] and l[1]>=l[2]:
ind=1'''
#step+=1
#print step,i
#if found==0:
mn=min([step,mn])
print mn
| 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;
cin >> a >> b;
vector<int> t;
t.push_back(b);
t.push_back(b * 2 - 1);
while (t.back() < a) {
int n = t.size();
t.push_back(t[n - 1] + t[n - 2] - 1);
}
cout << (t.size() + 1) << endl;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer(br.readLine());
int x = Integer.parseInt(str.nextToken());
int y = Integer.parseInt(str.nextToken());
int a = y ;
int b = y;
int c = y ;
int count = 0;
int array [] = new int[3];
array[0] = a;
array[1] = b;
array[2] = c;
Arrays.sort(array);
while(! (array[0] == x)){
//System.out.println("2w");
count++;
array[0] = Math.min((array[2]+array[1]-1),x);
Arrays.sort(array);
}
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.*;
import java.math.*;
/*
* Created by Epsilon Alpha on 12-Sep-16 at 4:10 AM.
*/
public final class DeEvolution
{
public static void main(String[] args) throws Exception
{
Parser Reader = new Parser(System.in);
OutputWriter Writer = new OutputWriter(System.out);
int x = Reader.nextInt();
int y = Reader.nextInt();
int[] ar = {y,y,y};
int steps = 0;
while(ar[0]!=x)
{
ar[0]=Math.min(x,ar[1]+ar[2]-1);
Arrays.sort(ar);
steps++;
}
Writer.println(steps);
Writer.close();
}
private static class Parser
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Parser(InputStream in)
{
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public int nextInt() throws Exception
{
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
public long nextLong() throws Exception
{
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
public String next() throws Exception
{
StringBuffer ret = new StringBuffer();
byte c = read();
while (c <= ' ') c = read();
do
{
ret = ret.append((char) c);
c = read();
} while (c > ' ');
return ret.toString();
}
private void fillBuffer() throws Exception
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws Exception
{
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
}
private static class OutputWriter
{
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream)
{
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)), true);
}
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 println(Object... objects)
{
print(objects);
writer.println();
}
public void close()
{
writer.close();
}
public void flush()
{
writer.flush();
}
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | # -*- coding: utf-8 -*-
import sys
def some_func():
"""
"""
m,n = map(int,sys.stdin.readline().split())
count = 0
x,y,z = n,n,n
while True:
temp = z+y-1
if temp<m:
x,y,z = y,z,temp
count+=1
else:
count+=1
break
print count+2
if __name__ == '__main__':
some_func()
| 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;
template <class T>
T power(T N, T P) {
return (P == 0) ? 1 : N * power(N, P - 1);
}
int main() {
int x, y, ok;
cin >> x >> y;
priority_queue<int> pq;
pq.push(y);
pq.push(y);
pq.push(y);
int cnt = 0;
while (1) {
int a = pq.top();
pq.pop();
int b = pq.top();
pq.pop();
int c = pq.top();
pq.pop();
cnt++;
if (a == b && b == c && c == x) break;
if (a + b - 1 >= x)
ok = x;
else
ok = a + b - 1;
pq.push(ok);
pq.push(a);
pq.push(b);
}
printf("%d\n", cnt - 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 | #include <bits/stdc++.h>
using namespace std;
int x, y, cnt, a, b, c, mn;
int main() {
cin >> x >> y;
a = y;
b = y;
c = y;
while (a != x || b != x || c != x) {
mn = min(a, min(b, c));
if (mn == a)
a = min(x, b + c - 1);
else if (mn == b)
b = min(x, a + c - 1);
else
c = min(x, a + b - 1);
cnt++;
}
cout << cnt;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | [x,y] = map(int,raw_input().split())
time = 0
a = b = c = y
while True:
if a >= x and b >= x and c >= x:
print time
break
time += 1
if time % 3 == 1:
a = b + c - 1
elif time % 3 == 2:
b = a + c - 1
else:
c = a + b - 1
| PYTHON |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Main {
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
static boolean canTriangle(int a, int b, int c) {
return a + b > c && b + c > a && a + c > b;
}
void run(InputReader in, PrintWriter out) {
int x = in.nextInt();
int y = in.nextInt();
int a = y, b = y, c = y;
int op = 0;
while (a < x || b < x || c < x) {
op++;
int[] arr = {a, b, c};
Arrays.sort(arr);
a = arr[0];
b = arr[1];
c = arr[2];
//out.println(a + ", " + b + ", " + c);
int l = a, r = x + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (canTriangle(mid, b, c)) l = mid;
else r = mid;
}
a = l;
}
out.println(op);
}
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
new Thread(null, () -> { new Main().run(in, out); }, "1", 1L << 26).run();
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 |
# (a[0], a[1], a[2]) => (y, y, y)
def triangle(a, y, prt=False):
if min(a) >= y:
return 0
elif a[1] + a[2] - 1 >= y:
return triangle([a[1], a[2], y], y) + 1
else:
return triangle([a[1], a[2], a[1] + a[2] - 1], y) + 1
def main():
x, y = list(map(int, input().split(' ')))
print(triangle([y, y, y], x))
if __name__ == '__main__':
main() | PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
File file = new File("in.txt");
InputStream inputStream = null;
// try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
Integer desiredLength = in.nextInt();
Integer startLength = in.nextInt();
Integer a = startLength;
Integer b = startLength;
Integer c = startLength;
Integer maxDist = desiredLength - a;
int steps = 0;
while(maxDist > 0){
int distA = desiredLength - a;
int distB = desiredLength - b;
int distC = desiredLength - c;
if (distA >= distB && distA >=distC){
a = Math.min(desiredLength, Math.abs(b + c) - 1);
}
else if (distB >= distA && distB >=distC){
b = Math.min(desiredLength, Math.abs(a + c) - 1);
}
else if (distC >= distA && distC >=distB){
c = Math.min(desiredLength, Math.abs(a + b) - 1);
}
maxDist = Math.max(Math.max(desiredLength - a, desiredLength - b),desiredLength - c);
steps+=1;
}
out.println(steps);
}
}
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 String nextLine(){
try {
return reader.readLine();
} catch (IOException e){
throw new RuntimeException(e);
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() { return Long.parseLong(next()); }
}
class Pair<F, S> {
public final F first;
public final S second;
public Pair(F first, S second) {
this.first = first;
this.second = second;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) {
return false;
}
Pair<?, ?> p = (Pair<?, ?>) o;
return Objects.equals(p.first, first) && Objects.equals(p.second, second);
}
@Override
public int hashCode() {
return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
}
@Override
public String toString() {
return "(" + first + ", " + second + ')';
}
} | 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
i=lambda:sys.stdin.readline().strip()
sys.setrecursionlimit(99999999)
ii=lambda:map(int,i().split(" "))
x,y=ii()
sides=[y,y,y]
acc=0
while sides[0]<>x or sides[1]<>x or sides[2]<>x:
sides.sort()
sides[0]=min(x,sides[1]+sides[2]-1)
acc+=1
print acc | 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 a, b, cot;
bool flag;
int main() {
scanf("%d%d", &a, &b);
int b1, b2, b3;
b1 = b, b2 = b, b3 = b;
while (1) {
flag = 0;
if (b2 != a) {
if (b1 + b3 <= a) {
b2 = b1 + b3 - 1;
cot++;
} else {
b2 = a;
cot++;
}
flag = 1;
}
if (b3 != a) {
if (b1 + b2 <= a) {
b3 = b1 + b2 - 1;
cot++;
} else {
b3 = a;
cot++;
}
flag = 1;
}
if (b1 != a) {
if (b2 + b3 <= a) {
b1 = b2 + b3 - 1;
cot++;
} else {
b1 = a;
cot++;
}
flag = 1;
}
if (!flag) break;
}
printf("%d\n", cot);
}
| 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 | n,m = map(int,input().split())
s = [m,m,m]
ans = 0
while s[0] < n:
val = min(n,s[1]+s[2]-1)
s[0] = s[1]
s[1] = s[2]
s[2] = val
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 size1 = 4e5;
const int INF = 2e9;
int main() {
int x, y;
cin >> y >> x;
int a = x, b = x, c = x;
int k = 0;
while (a != y) {
k++;
a = min(y, b + c - 1);
if (a > b) {
swap(a, b);
}
if (b > c) {
swap(b, c);
}
}
cout << k;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | x,y=map(int,input().split())
a,b,c=y,y,y
turn=0
while True:
if a>=x and b>=x and c>=x:
print(turn)
break
if turn%3==0:
a=b+c-1
elif turn%3==1:
b=c+a-1
else:
c=a+b-1
turn+=1 | PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> m >> n;
long long int x1 = n, x2 = n, x3 = n, count = 0;
while (1) {
if (x2 + x3 > m) {
count += 3;
break;
}
x1 = x2 + x3 - 1;
count++;
if (x1 + x3 > m) {
count += 3;
break;
}
x2 = x1 + x3 - 1;
count++;
if (x1 + x2 > m) {
count += 3;
break;
}
x3 = x1 + x2 - 1;
count++;
}
cout << count;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
scanf("%d%d", &y, &x);
int a[3];
a[0] = x;
a[1] = x;
a[2] = x;
int ans = 0;
while (1) {
sort(a, a + 3);
if (a[0] == a[1] && a[1] == a[2] && a[2] == y) {
printf("%d\n", ans);
return 0;
}
a[0] = min(y, a[1] + a[2] - 1);
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 read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int s[5];
int n, ans = 0;
int main() {
n = read();
s[1] = s[2] = s[3] = read();
while (s[1] != n || s[2] != n || s[3] != n) {
for (int i = 1; i <= 2; i++)
for (int j = i + 1; j <= 3; j++)
if (s[i] < s[j]) {
int t = s[i];
s[i] = s[j];
s[j] = t;
}
s[3] = min(n, s[1] + s[2] - 1);
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 | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int test_cases = 1;
Solver s = new Solver();
for (int i = 1; i <= test_cases; i++) {
s.solve(i, in, out);
}
out.close();
}
}
class Solver {
void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
int k = in.nextInt();
int[] a = new int[3];
Arrays.fill(a, k);
int x = 0;
int p = 0;
while (true) {
if (foo(a, n)) break;
int l = a[p], r = n;
if (a[p] == n) {
p = (p + 1) % 3;
continue;
}
while (l <= r) {
int mid = (l + r) >> 1;
if (bar(mid, a, p)) {
l = mid + 1;
}
else r = mid - 1;
// out.println(l + " Binary Search " + r);
}
a[p] = r;
// out.println(Arrays.toString(a));
p = (p + 1) % 3;
x++;
}
out.println(x);
}
private boolean bar(int mid, int[] a, int p) {
if (p == 0) {
if (mid + a[1] > a[2] && mid + a[2] > a[1] && a[1] + a[2] > mid) return true;
}
else if (p == 1) {
if (mid + a[0] > a[2] && mid + a[2] > a[0] && a[0] + a[2] > mid) return true;
}
else {
if (mid + a[1] > a[0] && mid + a[0] > a[1] && a[1] + a[0] > mid) return true;
}
return false;
}
private boolean foo(int[] a, int k) {
for (int i = 0; i < a.length; i++) {
if (a[i] != k) return false;
}
return true;
}
}
class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader()
{
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 | #include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const double EPS = 1e-8;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
int main() {
std::ios_base::sync_with_stdio(false);
int x, y;
cin >> y >> x;
vector<int> side(3, x);
int res = 0;
int turn = 0;
while (1) {
if (side[turn] != y) {
res += 1;
int len = 0;
for (int i = 0; i < 3; i++)
if (i != turn) len += side[i];
side[turn] = min(y, len - 1);
}
bool valid = true;
for (int i = 0; i < 3; i++)
if (side[i] != y) valid = false;
if (valid) break;
turn = (turn + 1) % 3;
}
cout << res << endl;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long x, y, a[3];
cin >> x >> y;
a[0] = a[1] = a[2] = y;
long i = 0, cnt = 0;
while (a[0] != x && a[1] != x && a[2] != x) {
if (i > 2) i = 0;
switch (i) {
case 0: {
a[0] = a[1] + a[2] - 1;
if (a[0] > x) a[0] = x;
} break;
case 1: {
a[1] = a[0] + a[2] - 1;
if (a[1] > x) a[1] = x;
} break;
case 2: {
a[2] = a[1] + a[0] - 1;
if (a[2] > x) a[2] = x;
} break;
}
i++;
cnt++;
}
cout << (cnt + 2);
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
from __future__ import print_function # for PyPy2
# from itertools import permutations
# from functools import cmp_to_key # for adding custom comparator
# from fractions import Fraction
from collections import *
from sys import stdin
# from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x : reversed(range(x))
mod = int(1e9)+7
inf = float("inf")
l = gil()
l.sort()
t = [l[0]]*3
ans = 0
while t[0] != l[1]:
t[0] = min(l[1], sum(t[1:])-1)
t.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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int p, q;
while (cin >> p >> q) {
int ans = 0;
int a, b, c;
a = b = c = q;
while (c < p) {
int newC = b + c - 1;
a = b;
b = c;
c = newC;
ans++;
}
if (a != p) ans++;
if (b != p) ans++;
cout << ans << endl;
}
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101",
"0110", "0111", "1000", "1001", "1010", "1011",
"1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b) { return a < b ? a : b; }
inline int Max(int a, int b) { return a > b ? a : b; }
inline long long Min(long long a, long long b) { return a < b ? a : b; }
inline long long Max(long long a, long long b) { return a > b ? a : b; }
inline bool is_in(int r, int c) { return r >= 0 && r < n && c >= 0 && c < m; }
int a[4];
int main() {
while (scanf("%d %d", &n, &m) == 2) {
a[2] = a[1] = a[0] = m;
int ans = 0;
while (a[0] != n) {
a[0] = Min(n, a[1] + a[2] - 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 | import java.util.*;
import java.io.*;
import java.math.*;
import java.math.BigInteger;
public class test {
static long sum=0,sum1=Long.MAX_VALUE;
static int count;
public static void main(String args[])
{
InputReader in = new InputReader(System.in);
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
int x=in.nextInt();
int y=in.nextInt();
int x1,x2,x3,ans=0;
int arr[]=new int[3];
if(2*y>x)
{
out.println(3);
}
else if(2*y==x)
{
out.println(4);
}
else
{
int count=0;
arr[0]=y;
arr[1]=y;
arr[2]=y;
ans++;
while(arr[0]!=x||arr[1]!=x||arr[2]!=x)
{
arr[0]=arr[1]+arr[2]-1;
if(arr[0]>x)
arr[0]=x;
Arrays.sort(arr);
count++;
}
out.println(count);
}
out.close();
}
static long fact(long x)
{
long i=x,mul=1;
while(i>0)
{
mul=(mul%1000000007)*(i%1000000007)%1000000007;
i--;
}
return mul;
}
static long output(ArrayList<Integer> h[],int j,boolean[] v)
{
int k;
v[j]=true;
sum++;
for(k=0;k<h[j].size();k++)
{
if(v[h[j].get(k)]==false)
{
output(h,h[j].get(k),v);
}
}
return sum;
}
static long func(boolean v[],int j,ArrayList<Integer> h[],long ban[])
{
v[j]=true;
int k;
long sum=0;
sum=sum+ban[j];
//System.out.println(h[j].size());
for(k=0;k<h[j].size();k++)
{
if(v[h[j].get(k)]==false)
{
v[h[j].get(k)]=true;
sum+=func(v,h[j].get(k),h,ban);
}
}
return sum;
}
/*static class Graph {
private static Deque<Integer> stack = new ArrayDeque<Integer>();
private int least,count,v;
Set<Integer>[] cities;
private int[] risk;
Graph(int n,String[] risk){
cities = new HashSet[n];
this.risk = new int[n];
for(int i =0;i<n;i++){
cities[i] = new HashSet<>();
}
for(int i =0;i<n;i++){
this.risk[i] = Integer.parseInt(risk[i]);
}
visited = new boolean[n];
}
public void add(int x,int y){
cities[x].add(y);
cities[y].add(x);
}
}*/
static int root(int arr[],int i)
{
while(arr[i]!=i)
{
i=arr[i];
}
return i;
}
static boolean find(int arr[],int a,int b)
{
if(root(arr,a)==root(arr,b))
{
return true;
}
else
return false;
}
static void weighted_union(int arr[],int size[],int a,int b)
{
int root_a=root(arr,a);
int root_b=root(arr,b);
if(root_a!=root_b)
{
if(size[root_a]<size[root_b])
{
arr[root_a]=arr[root_b];
size[root_b]+=size[root_a];
}
else
{
arr[root_b]=arr[root_a];
size[root_a]+=size[root_b];
}
count--;
}
}
static class Pair implements Comparable<Pair>
{
private long first;
private long index;
//private long second;;
public Pair(long i, long j)
{
this.first = i;
this.index = j;
}
public long getFirst() { return first; }
//public long getSecond() { return second; }
public long getIndex() { return index ;}
public void setFirst(long k) { this.first=k ; }
public void setIndex(long k) { this.index=k ;}
//public void setSecond(long k) { this.second=k ;}
@Override
public int compareTo(Pair o)
{
return Long.compare(this.first, o.first);
}
}
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 | import java.io.*;
import java.util.*;
public class C
{
public static void main(String[] args)
{
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int a = sc.nextInt(), b = sc.nextInt();
ArrayList<Integer> inp = new ArrayList<Integer>();
inp.add(b);
inp.add(b);
inp.add(b);
Collections.sort(inp);
int ans = 0;
while(true) {
//System.out.printf("%d %d %d %d\n", inp.get(0), inp.get(1), inp.get(2), a);
if( (inp.get(0) == a) )
break;
ans++;
inp.remove(0);
inp.add(Math.min(inp.get(0) + inp.get(1) - 1, a));
Collections.sort(inp);
}
out.println(ans);
out.close();
}
// PrintWriter for faster output
public static PrintWriter out;
// MyScanner class for faster input
public static class MyScanner
{
BufferedReader br;
StringTokenizer st;
public MyScanner()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
boolean hasNext()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
return false;
}
}
return true;
}
String next()
{
if (hasNext())
return st.nextToken();
return null;
}
int nextInt()
{
return Integer.parseInt(next());
}
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 | eKnBQaHTzrUcYtwjiVCG = map
eKnBQaHTzrUcYtwjiVCo = int
eKnBQaHTzrUcYtwjiVCX = input
eKnBQaHTzrUcYtwjiVCA = sorted
eKnBQaHTzrUcYtwjiVCN = min
eKnBQaHTzrUcYtwjiVCF = print
x, y = eKnBQaHTzrUcYtwjiVCG(
eKnBQaHTzrUcYtwjiVCo, eKnBQaHTzrUcYtwjiVCX().split())
a, b, c = y, y, y
k = 0
while a != x:
a, b, c = eKnBQaHTzrUcYtwjiVCA([eKnBQaHTzrUcYtwjiVCN(x, b+c-1), b, c])
k += 1
eKnBQaHTzrUcYtwjiVCF(k)
| PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
scanf("%d%d", &x, &y);
int a[5], cnt = 0;
a[0] = a[1] = a[2] = y;
while (1) {
sort(a, a + 3);
if (a[0] < x) {
a[0] = a[1] + a[2] - 1;
} else {
break;
}
cnt++;
}
printf("%d\n", cnt);
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | from random import random
import math
import re
import fractions
a, b = map(int, raw_input().split(" "))
# BF
if a == b:
print 0
else:
r = [b, b, b]
i = 0
while r[2] < a:
t = min(r[0] + r[1] - 1, a)
r = [t, r[0], r[1]]
# print r
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 | import java.util.Scanner;
public class DeEvolution {
public static int[] sort(int[] edges) {
int a = edges[0];
int b = edges[1];
int c = edges[2];
if (b < a && b <= c) {
int temp = a;
a = b;
b = temp;
}
else if(c < a && c <= b) {
int temp = a;
a = c;
c = temp;
}
edges[0] = a;
edges[1] = b;
edges[2] = c;
return edges;
}
public static int[] newTriangle(int[] edges, int x) {
int[] sorted = sort(edges);
int newEdge = edges[1] + edges[2] - 1;
if (newEdge > x) {
newEdge = x;
}
sorted[0] = newEdge;
return sorted;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
int y = scan.nextInt();
int[] edges = new int[3];
for (int i = 0; i < 3; i++) {
edges[i] = y;
}
int times = 0;
while (edges[0] != x || edges[1] != x || edges[2] != x) {
edges = newTriangle(edges, x);
times++;
}
System.out.println(times);
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
int a = min(x, y);
int b = max(x, y);
int arr[3];
for (int i = 0; i < 3; i++) {
arr[i] = a;
}
long long res = 0;
while (1) {
sort(arr, arr + 3);
int x = arr[1] + arr[2] - 1;
if (arr[0] == b) break;
arr[0] = min(b, x);
res++;
}
cout << res << endl;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1E5 + 5;
const int MOD = 1E9 + 7;
const int MAXVALUE = 1E9 + 10;
int x, y, ret = 0;
int main() {
cin >> x >> y;
int a[5];
a[0] = a[1] = a[2] = y;
while (true) {
if (a[0] == a[1] && a[1] == a[2] && a[2] == x) break;
sort(a, a + 3);
a[0] = max(a[2] + a[1] - 1, y);
if (a[0] > x) a[0] = x;
ret++;
}
cout << ret << endl;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 |
/**
* Author:-Harsh Chaudhari
* College:-DA-IICT
*/
import java.util.*;
import java.io.*;
public class C712 {
public static void main(String[] args) {
InputReader s = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
/*My code starts here.*/
int n = s.nextInt(), k = s.nextInt();
int a = 2 * k - 1,b = n,c = n;
int count = 0;
int arr[] = new int[3];
arr[0] = 2*k-1;
arr[1] = k;
arr[2] = k;
if(n < 2 * k){
out.println("3");
}
else if(n==k){
out.println("0");
}
else{
while(arr[0]!=arr[2]){
arr[0] = arr[1] + arr[2] - 1;
if(arr[0]>n)
arr[0] = n;
Arrays.sort(arr);
count++;
//System.out.println(Arrays.toString(arr));
}
out.println(count);
}
/*My code ends here.*/
out.close();
}
static long PowerMod(long a, long b, long m) {
long tempo;
if (b == 0)
tempo = 1;
else if (b == 1)
tempo = a;
else {
long temp = PowerMod(a, b / 2, m);
if (b % 2 == 0)
tempo = (temp * temp) % m;
else
tempo = ((temp * temp) % m) * a % m;
}
return tempo;
}
static class Node implements Comparable<Node> {
int num, freq, idx;
public Node(int u, int v, int idx) {
this.num = u;
this.freq = v;
this.idx = idx;
}
public int compareTo(Node n) {
if (this.freq == n.freq)
return Integer.compare(this.num, n.num);
return Integer.compare(-this.freq, -n.freq);
}
}
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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* Created by Admin on 16.09.2016.
*/
public class C_712 {
static int get_i_min(int a[]){
int min = a[0], mini = 0;
for (int i = 1; i < 3; i++) {
if(a[i] < min){
min = a[i];
mini = i;
}
}
return mini;
}
static int get_i_max(int a[]){
int max = a[0], maxi = 0;
for (int i = 1; i < 3; i++) {
if(a[i] > max){
max = a[i];
maxi = i;
}
}
return maxi;
}
static int get_i_max_2(int a[]){
int maxi_2 = 0;
int maxi = get_i_max(a); int mini = get_i_min(a);
for (int i = 0; i < 3; i++) {
if (i != maxi && i != mini){
maxi_2 = i;
}
}
return maxi_2;
}
static boolean check(int a[], int y){
if (a[0] != y){
return false;
}else if (a[1] != y){
return false;
}else if (a[2] != y){
return false;
}else {
return true;
}
}
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer(br.readLine());
int x = Integer.parseInt(str.nextToken());
int y = Integer.parseInt(str.nextToken());
int a[] = {y, y, (y+y-1 > x) ? (x) : (y+y-1)};
int ans = 1;
while(!check(a, x)){
int MIN = get_i_min(a), MAX = get_i_max(a), MAX_2 = get_i_max_2(a);
a[MIN] = (a[MAX] + a[MAX_2] - 1 > x) ? (x) : (a[MAX] + a[MAX_2] - 1);
ans++;
}
System.out.println(ans);
}
}
| JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.util.*;
public class Main
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
String str[]=s.split(" ");
int x=Integer.parseInt(str[0]);
int y=Integer.parseInt(str[1]);
int arr[]=new int[3];
arr[0]=arr[1]=arr[2]=y;
int count=0;
while(true)
{
Arrays.sort(arr);
if(arr[0]>=x)
break;
arr[0]=arr[1]+arr[2]-1;
count++;
}
System.out.println(count);
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.util.*;
import java.math.*;
public class Solve3 {
static boolean isValid(int a, int b, int c) {
return a + b > c && a + c > b && b + c > a;
}
public static void main(String[] args) {
MyScanner scanner = new MyScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int a = scanner.nextInt();
int b = scanner.nextInt();
if(a > b) {
int c = b;
b = a; a = c;
}
int a1 = a, b1 = a, c1 = a;
int count = 0;
while(a1 < b || b1 < b || c1 < b)
{
//System.out.println(a1 + " " + b1 + " " + c1);
int preva = a1;
int prevb = b1;
int prevc = c1;
int c = Math.min(b, b1+c1-1);
a1 = b1;
b1 = c1;
c1 = c;
count++;
if(a1==preva&&b1==prevb&&c1==prevc)break;
}
out.println(a1 != b || b1 != b || c1 != b ? -1 : count);
out.close();
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
int main() {
long x, y, a, b, c, tmp, count = 0;
scanf("%ld%ld", &x, &y);
a = y;
b = y;
c = y;
while (c != x) {
tmp = a + b - 1;
if (tmp > x) tmp = x;
c = b;
b = a;
a = tmp;
count++;
}
printf("%ld\n", count);
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class P712C {
public void run() throws Exception {
int aa = nextInt(), mm = nextInt(), a = Math.min(aa, mm), b = a, c = a, m = Math.max(aa, mm), k = 0;
while (a != m) {
a = b;
b = c;
c = Math.min(m, a + b - 1);
k++;
}
println(k);
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedOutputStream(System.out));
new P712C().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
int gcd(int a, int b) {
return ((b > 0) ? gcd(b, a % b) : a);
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int x,y,max,min,mid;
long cnt=0;
x=sc.nextInt();y=sc.nextInt();
int[] arr=new int[3];
arr[0]=y;
arr[1]=y;
arr[2]=y;
while(true){
arr[0]=(arr[1]+arr[2]-1);
Arrays.sort(arr);
cnt++;
if(arr[0]>=x){
break;
}
}
System.out.println(cnt);
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
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);
PrintWriter out = new PrintWriter(System.out);
int x = sc.nextInt(), y = sc.nextInt();
int[] a = new int[3];
a[2] = a[1] = a[0] = y;
int sec = 0;
while(true)
{
if(a[0] == a[1] && a[1] == a[2] && a[2] == x)
break;
a[0] = Math.min(x, a[1] + a[2] -1);
Arrays.sort(a);
sec++;
}
out.println(sec);
out.flush();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream System)
{
br = new BufferedReader(new InputStreamReader(System));
}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine()throws IOException
{
return br.readLine();
}
public int nextInt() throws IOException
{
return Integer.parseInt(next());
}
public char nextChar()throws IOException
{
return next().charAt(0);
}
public Long nextLong()throws IOException
{
return Long.parseLong(next());
}
public boolean ready() throws IOException
{
return br.ready();
}
}
}
| 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.Point;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.GuardedObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.io.InputStream;
import java.math.BigInteger;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in;
PrintWriter out;
in=new FastScanner(System.in);
out=new PrintWriter(System.out);
//in=new FastScanner(new FileInputStream(new File("C://Users//KANDARP//Desktop//coding_contest_creation (1).txt")));
TaskC solver = new TaskC();
long var=System.currentTimeMillis();
solver.solve(1, in, out);
/*if(System.getProperty("ONLINE_JUDGE")==null){
out.println("["+(double)(System.currentTimeMillis()-var)/1000+"]");
}*/
out.close();
}
}
class Pair {
long x,y,index;
long r1,r2;
Pair(long x,long y,int index){
this.x=x;
this.y=y;
this.index=index;
}
public String toString(){
return this.x+" "+this.y+" ";
}
}
class Edge implements Comparable<Edge>{
int u;
int v;
int time;
long cost;
long wcost;
public Edge(int u,int v,long cost,long wcost){
this.u=u;
this.v=v;
this.cost=cost;
this.wcost=wcost;
time=Integer.MAX_VALUE;
}
public int other(int x){
if(u==x)return v;
return u;
}
@Override
public int compareTo(Edge o) {
// TODO Auto-generated method stub
return Long.compare(cost, o.cost);
}
}
class queary{
int type;
int l;
int r;
int index;
queary(int type,int l,int r,int index){
this.type=type;
this.l=l;
this.r=r;
this.index=index;
}
}
class TaskC {
static long mod=1000000007;
/* static int prime_len=1000010;
static int prime[]=new int[prime_len];
static long n_prime[]=new long[prime_len];
static ArrayList<Integer> primes=new ArrayList<>();
static{
for(int i=2;i<=Math.sqrt(prime.length);i++){
for(int j=i*i;j<prime.length;j+=i){
prime[j]=i;
}
}
for(int i=2;i<prime.length;i++){
n_prime[i]=n_prime[i-1];
if(prime[i]==0){
n_prime[i]++;
}
}
// System.out.println("end");
// prime[0]=true;
// prime[1]=1;
}
/*
* long pp[]=new long[10000001];
pp[0]=0;
pp[1]=1;
for(int i=2;i<pp.length;i++){
if(prime[i]!=0){
int gcd=(int)greatestCommonDivisor(i/prime[i], prime[i]);
pp[i]=(pp[i/prime[i]]*pp[prime[i]]*gcd)/pp[(int)gcd];
}
else
pp[i]=i-1;
}
}
* */
class TrieNode{
int value;
TrieNode children[];
public TrieNode(int value,TrieNode children[] ){
this.value=value;
this.children=children;
}
}
class Trie{
TrieNode root;
int count;
public Trie(TrieNode root,int count){
this.root=root;
this.count=count;
}
}
public void insert(Trie t,char key[]){
t.count++;
int length=key.length;
int level=0;
TrieNode current=t.root;
if(current==null){
t.root=new TrieNode(0, new TrieNode[26]);
current=t.root;
}
for(level=0;level<length;level++){
int index=key[level]-'a';
if(current.children[index]==null){
current.children[index]=new TrieNode(0,new TrieNode[26]);
}
current=current.children[index];
}
current.value=t.count;
}
public int search(Trie t,char key[]){
TrieNode current=t.root;
if(current==null){
return 0;
}
int length=key.length;
int level=0;
for(level=0;level<length;level++){
int index=key[level]-'a';
if(current.children[index]==null){
return 0;
}
current=current.children[index];
}
return current.value;
}
class point{
int x;
int y;
}
int orientation(point p, point q, point r)
{
int val = (q.y - p.y) * (r.x - q.x) -
(q.x - p.x) * (r.y - q.y);
if (val == 0) return 0; // colinear
return (val > 0)? 1: 2; // clock or counterclock wise
}
public void solve(int testNumber, FastScanner in, PrintWriter out) throws IOException {
int x=in.nextInt();
int y=in.nextInt();
int ans=0;
//int a=y,b=y,c=y;
int a[]=new int[3];
for(int i=0;i<3;i++){
a[i]=y;
}
while(a[0]!=x || a[1]!=x || a[2]!=x){
Arrays.sort(a);
a[0]=Math.min(x, a[1]+a[2]-1);
ans++;
}
out.println(ans);
}
public boolean isTriangle(int x,int y,int z){
if(x+y>z && x+z>y && y+z>x){
return true;
}
return false;
}
public long optimize(long x){
long y=x;
if(x%10<5){
x=x-x%10;
}
else{
x=x+(10-x%10);
}
return y-x;
}
public static long[][] matrixexpo(long m[][],String n,long mod){
if(n.equals("1")){
return m.clone();
}
if(n.equals("10")){
return mulmatrix(m, m , mod);
}
else{
long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
temp=mulmatrix(temp, temp, mod);
if(n.charAt(n.length()-1)=='0')return temp;
else return mulmatrix(temp, m,mod);
}
}
public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
long ans[][]=new long[m1.length][m2[0].length];
for(int i=0;i<m1.length;i++){
for(int j=0;j<m2[0].length;j++){
for(int k=0;k<m1.length;k++){
ans[i][j]+=(m1[i][k]*m2[k][j]);
ans[i][j]%=mod;
}
}
}
return ans;
}
long pow(long x,long y,long mod){
if(y<=0){
return 1;
}
if(y==1){
return x%mod;
}
long temp=pow(x,y/2,mod);
if(y%2==0){
return (temp*temp)%mod;
}
else{
return (((temp*temp)%mod)*x)%mod;
}
}
static long greatestCommonDivisor (long m, long n){
long x;
long y;
while(m%n != 0){
x = n;
y = m%n;
m = x;
n = y;
}
return n;
}
static void dfs(List<Integer>[] graph, boolean[] used, List<Integer> res, int u,int parent,List<Integer> collection) {
used[u] = true;
Integer uu=new Integer(u);
collection.add(uu);
for (int v : graph[u]){
if (!used[v]){
dfs(graph, used, res, v,u,collection);
}
else if(collection.contains(v)){
System.out.println("Impossible");
System.exit(0);
}
}
collection.remove(uu);
res.add(u);
}
public static List<Integer> topologicalSort(List<Integer>[] graph) {
int n = graph.length;
boolean[] used = new boolean[n];
List<Integer> res = new ArrayList<>();
for (int i = 0; i < n; i++)
if (!used[i])
dfs(graph, used, res, i,-1,new ArrayList<Integer>());
Collections.reverse(res);
return res;
}
}
class LcaSparseTable {
int len;
int[][] up;
int[][] max;
int[] tin;
int[] tout;
int time;
int []lvel;
void dfs(List<Integer>[] tree, int u, int p) {
tin[u] = time++;
lvel[u]=lvel[p]+1;
up[0][u] = p;
if(u!=p)
//max[0][u]=weight(u,p);
for (int i = 1; i < len; i++)
{
up[i][u] = up[i - 1][up[i - 1][u]];
max[i][u]=Math.max(max[i-1][u],max[i-1][up[i-1][u]]);
}
for (int v : tree[u])
if (v != p)
dfs(tree, v, u);
tout[u] = time++;
}
public LcaSparseTable(List<Integer>[] tree, int root) {
int n = tree.length;
len = 1;
while ((1 << len) <= n) ++len;
up = new int[len][n];
max=new int[len][n];
tin = new int[n];
tout = new int[n];
lvel=new int[n];
lvel[root]=0;
dfs(tree, root, root);
}
boolean isParent(int parent, int child) {
return tin[parent] <= tin[child] && tout[child] <= tout[parent];
}
public int lca(int a, int b) {
if (isParent(a, b))
return a;
if (isParent(b, a))
return b;
for (int i = len - 1; i >= 0; i--)
if (!isParent(up[i][a], b))
a = up[i][a];
return up[0][a];
}
public long max(int a,int b){
int lca=lca(a,b);
// System.out.println("LCA "+lca);
long ans=0;
int h=lvel[a]-lvel[lca];
// System.out.println("Height "+h);
int index=0;
while(h!=0){
if(h%2==1){
ans=Math.max(ans,max[index][a]);
a=up[index][a];
}
h/=2;
index++;
}
h=lvel[b]-lvel[lca];
// System.out.println("Height "+h);
index=0;
while(h!=0){
if(h%2==1){
ans=Math.max(ans,max[index][b]);
b=up[index][b];
}
h/=2;
index++;
}
return ans;
}
static void dfs1(List<Integer>[] graph, boolean[] used, List<Integer> res, int u) {
used[u] = true;
for (int v : graph[u])
if (!used[v])
dfs1(graph, used, res, v);
res.add(u);
}
int phi(int n) {
int res = n;
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
}
res -= res / i;
}
}
if (n != 1) {
res -= res / n;
}
return res;
}
public static long[][] mulmatrix(long m1[][],long m2[][],long mod){
long ans[][]=new long[m1.length][m2[0].length];
for(int i=0;i<m1.length;i++){
for(int j=0;j<m2[0].length;j++){
for(int k=0;k<m1.length;k++){
ans[i][j]+=(m1[i][k]*m2[k][j]);
ans[i][j]%=mod;
}
}
}
return ans;
}
public static long[][] matrixexpo(long m[][],String n,long mod){
if(n.equals("1")){
return m.clone();
}
if(n.equals("10")){
return mulmatrix(m, m , mod);
}
else{
long temp [][]=matrixexpo(m,n.substring(0,n.length()-1),mod);
temp=mulmatrix(temp, temp, mod);
if(n.charAt(n.length()-1)=='0')return temp;
else return mulmatrix(temp, m,mod);
}
}
public static boolean isCompatible(long x[],long y[]){
for(int i=0;i<x.length-1;i++){
if(x[i]==y[i] && x[i+1]==y[i+1] && x[i]==x[i+1] && y[i]==y[i+1]){
return false;
}
}
return true;
}
long pow(long x,long y,long mod){
if(y<=0){
return 1;
}
if(y==1){
return x%mod;
}
long temp=pow(x,y/2,mod);
if(y%2==0){
return (temp*temp)%mod;
}
else{
return (((temp*temp)%mod)*x)%mod;
}
}
long no_of_primes(long m,long n,long k){
long count=0,i,j;
int primes []=new int[(int)(n-m+2)];
if(m==1) primes[0] = 1;
for(i=2; i<=Math.sqrt(n); i++)
{
j = (m/i); j *= i;
if(j<m)
j+=i;
for(; j<=n; j+=i)
{
if(j!=i)
primes[(int)(j-m)] = 1;
}
}
for(i=0; i<=n-m; i++)
if(primes[(int)i]==0 && (i-1)%k==0)
count++;
return count;
}
}
class SegTree {
int n;
static long constt=Long.parseLong("111111111111111111111111111111",2);
long t[];
long mod=(long)(1000000007);
SegTree(int n,long t[]){
this.n=n;
this.t=t;
build();
}
void build() { // build the tree
for (int i = n - 1; i >= 0; --i){
t[i]=(t[i<<1]&t[i<<1|1]);
}
}
void modify(int p, long value) { // set value at position p
for (t[p += n]=value; p > 1; p >>= 1) t[p>>1] = (t[p]&t[p^1]);
// System.out.println(Arrays.toString(t));
}
long query(int l, int r) { // sum on interval [l, r)
long res=constt;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if ((l&1)!=0) res=res&t[l++];
if ((r&1)!=0) res=res&t[--r];
}
return res;
}
//
//
//
}
class FastScanner
{
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar;
private int snumChars;
private SpaceCharFilter filter;
public FastScanner(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 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);
}
}
class UF {
private int[] parent; // parent[i] = parent of i
private byte[] rank; // rank[i] = rank of subtree rooted at i (never more than 31)
private int count; // number of components
public UF(int N) {
if (N < 0) throw new IllegalArgumentException();
count = N;
parent = new int[N];
rank = new byte[N];
for (int i = 0; i < N; i++) {
parent[i] = i;
rank[i] = 0;
}
}
public int find(int p) {
if (p < 0 || p >= parent.length) throw new IndexOutOfBoundsException();
while (p != parent[p]) {
parent[p] = parent[parent[p]]; // path compression by halving
p = parent[p];
}
return p;
}
public int count() {
return count;
}
public boolean connected(int p, int q) {
return find(p) == find(q);
}
public boolean union(int p, int q) {
int rootP = find(p);
int rootQ = find(q);
if (rootP == rootQ) return false;
// make root of smaller rank point to root of larger rank
if (rank[rootP] < rank[rootQ]) parent[rootP] = rootQ;
else if (rank[rootP] > rank[rootQ]) parent[rootQ] = rootP;
else {
parent[rootQ] = rootP;
rank[rootP]++;
}
count--;
return true;
}
}
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 3e6 + 7;
const int mod = 998244353;
const double eps = 1e-7;
int ca = 1;
int a[4];
int x, y;
void solve() {
scanf("%d%d", &x, &y);
int ans = 0;
a[0] = a[1] = a[2] = y;
while (a[0] < x || a[1] < x || a[2] < x) {
sort(a, a + 3);
a[0] = a[2] + a[1] - 1;
ans++;
}
cout << ans << endl;
}
int main() {
int t = 1;
while (t--) solve();
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int x, y, a[3], k;
int main() {
cin >> x >> y;
swap(x, y);
a[0] = a[1] = a[2] = x;
while (a[0] < y || a[1] < y || a[2] < y) {
if (a[0] > a[1]) swap(a[0], a[1]);
if (a[1] > a[2]) swap(a[1], a[2]);
if (a[0] > a[1]) swap(a[0], a[1]);
a[0] = min(y, a[1] + a[2] - 1);
k++;
}
cout << k;
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const long long int no = 3e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 3e3 + 1;
long long int ar[no], br[no], cr[no];
long long int ans = 0;
void calc(long long int x, long long int y, long long int z, long long int aim,
long long int t) {
if (x == aim and y == aim and z == aim) return;
if (t == 0) {
if (x == aim) {
calc(x, y, z, aim, t ^ 1);
return;
}
x = min(y + z - 1, aim);
ans++;
calc(x, y, z, aim, t ^ 1);
} else if (t == 1) {
if (y == aim) {
calc(x, y, z, aim, 2);
return;
}
y = min(x + z - 1, aim);
ans++;
calc(x, y, z, aim, 2);
} else {
if (z == aim) {
calc(x, y, z, aim, t ^ 2);
return;
}
z = min(x + y - 1, aim);
ans++;
calc(x, y, z, aim, t ^ 2);
}
}
void solve() {
long long int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0,
w = 0, k = 0;
cin >> n >> m;
calc(m, m, m, n, 0);
cout << ans;
}
inline void runn() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
for (long long int i = 1; i < t + 1; i++) {
solve();
}
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
priority_queue<int> qu;
int x, y;
cin >> x >> y;
int step = 0;
qu.push(y);
qu.push(y);
qu.push(y);
for (;;) {
int max1 = qu.top();
qu.pop();
int mid1 = qu.top();
qu.pop();
int min1 = qu.top();
qu.pop();
if (min1 == x && mid1 == x && x == max1) {
cout << step << endl;
break;
}
if (max1 + mid1 <= x) {
min1 = max1 + mid1 - 1;
step++;
} else {
min1 = x;
step++;
}
qu.push(min1);
qu.push(mid1);
qu.push(max1);
}
return 0;
}
| CPP |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 1e9;
const int mod = 1e9 + 7;
const long long INF = 1e18;
int x, y, a, b, c, res;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> x >> y;
if (x < y + y) {
return cout << 3, 0;
}
if (x == y + y) {
return cout << 4, 0;
}
a = b = c = y;
while (1) {
if (a == b && a == c && a == x) break;
a = min(x, b + c - 1);
++res;
if (a == b && a == c && a == x) break;
b = min(x, a + c - 1);
++res;
if (a == b && a == c && a == x) break;
c = min(x, a + b - 1);
++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 | x, y = map(int,input().split())
a = [y,y,y]
cnt = 0
while True:
if a[0] == a[1] == a[2] == x:
break
if a[1] + a[2] > x:
a[0] = x
else:
a[0] = a[1] + a[2] - 1
cnt+=1
a.sort()
print(cnt) | PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const string NAME = "712C";
int x, y;
void input() { cin >> x >> y; }
void solve() {
int a[] = {y, y, y}, res = 0;
while (a[0] != x) {
a[0] = min(x, a[1] + a[2] - 1);
sort(a + 0, a + 3);
res++;
}
cout << res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
input();
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 | x,y = map(int, raw_input().strip().split())
a = [y,y,y]
count = 0
while (True):
if (a[0] == a[1] == a[2] == x):
break
if (a[1] + a[2] > x):
a[0] = x
else:
a[0] = a[1] + a[2] - 1
count += 1
a.sort()
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 | x, y = map(int, raw_input().split())
r = [y] * 3
i = 0
while r[0] < x:
r[0] = min(r[1]+r[2] - 1, x)
r.sort()
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 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author wistful
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(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, Scanner in, PrintWriter out) {
int x = in.nextInt();
int y = in.nextInt();
int cnt = 0;
int z = y;
int t = y;
while (y < x) {
++cnt;
int v = z + t - 1;
y = z;
z = t;
t = v;
}
out.println(cnt);
}
}
}
| JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
int a[4];
while (~scanf("%d%d", &m, &n)) {
int sum = 0;
a[0] = n, a[1] = n, a[2] = n;
while (a[0] < m) {
sum++;
a[0] = a[1] + a[2] - 1;
sort(a, a + 3);
}
printf("%d\n", sum);
}
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 | g,a=[int(x) for x in input().split()]
b=c=a
s=0
while min(min(a,b),c)<g:
s+=1
l=[a,b,c]
l.sort()
a,b,c=l
a=min(g,c+b-1)
print(s) | 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 | n ,m=map(int,input().split())
a,b,c= m,m,m
cou =0
if(n==m):
print(0)
exit()
while(True):
if(a<b):
if(a<c):
a = min(b+c-1,n)
else:
c= min(a+b-1,n)
else:
if(b<c):
b=min(a+c-1,n)
else:
c= min(a+b-1,n)
cou+=1
if(a==n and b==n and c==n):
break
print(cou)
| PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
int ans = 0;
vector<int> v(3, y);
while (v[0] < x) {
v[0] = min(v[1] + v[2] - 1, x);
ans++;
sort(v.begin(), v.end());
}
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 | s, d = map(int, raw_input().split())
#Reversing the solution
d = [d] * 3
count = 0
while d[0] < s:
d[0] = min(d[2] + d[1] - 1, s)
d.sort()
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 | x,y = map(int,input().split())
arr = [y,y,y]
c = 0
t = 0
while True:
if(arr.count(x)==3):
break
if(t==0):
arr[0] = arr[1]+arr[2]-1
if(arr[0]>x):
arr[0] = x
t = 1
elif(t==1):
arr[1] = arr[0]+arr[2]-1
if(arr[1]>x):
arr[1] = x
t = 2
elif(t==2):
arr[2] = arr[0]+arr[1]-1
if(arr[2]>x):
arr[2] = x
t = 0
c += 1
print(c) | PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int x, y, a[4], sum;
int main() {
scanf("%d%d", &x, &y);
for (int i = 1; i < 4; i++) a[i] = y;
while (1) {
sort(a + 1, a + 4);
if (a[1] != x) {
sum++;
if (a[2] + a[3] > x)
a[1] = x;
else
a[1] = a[2] + a[3] - 1;
}
if (a[1] == a[2] && a[2] == a[3] && a[1] == x) break;
}
printf("%d", sum);
}
| 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 | A, B = map(int, raw_input().split())
count = 0
cur = [B] * 3
while cur[0] < A:
cur[0] = min(A, cur[1] + cur[2] - 1)
cur.sort()
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 maxn = 1e3 + 10;
int n, m, a[5];
int main() {
int x, y;
scanf("%d%d", &x, &y);
for (int i = 1; i <= 3; i++) {
a[i] = y;
}
int cnt = 0;
while (1) {
sort(a + 1, a + 1 + 3);
a[1] = a[2] + a[3] - 1;
cnt++;
if (a[1] > x && a[2] > x && a[3] > x) break;
}
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.*;
import java.math.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
//Scanner in=new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
List<Integer> list=new ArrayList<Integer>();
list.add(m);
list.add(m);
int ans=0;
while(true){
int leng=list.size();
int u=list.get(leng-2);
int v=list.get(leng-1);
int next=u+v-1;
if(next>=n){
ans=leng+1;
break;
}
list.add(next);
}
System.out.println(ans);
out.close();
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader (File f){
try{
br=new BufferedReader(new FileReader(f));
}catch(FileNotFoundException e){
e.printStackTrace();
}
}
public InputReader (InputStream in){
br=new BufferedReader(new InputStreamReader(in));
}
public String next(){
while(st==null||!st.hasMoreTokens()){
try{
st=new StringTokenizer(br.readLine());
}catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
public boolean hasNext(){
while(st==null||!st.hasMoreTokens()){
String s=null;
try{
s=br.readLine();
}catch(IOException e){
e.printStackTrace();
}
if(s==null)
return false;
st=new StringTokenizer(s);
}
return true;
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
}
} | JAVA |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | x, y = map(int, input().split())
counter = 0
x, y = min(x,y), max(x,y)
x1 = x
x2 = x
x3 = x
while y > x1 or y > x2 or y > x3:
if x1 != y:
x1 = min(x3 + x2 - 1, y)
counter += 1
if x2 != y:
x2 = min(x1 + x3 - 1, y)
counter += 1
if x3 != y:
x3 = min(x1 + x2 - 1, y)
counter += 1
# print(x1,x2,x3)
print(counter) | 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 ar[5], n, i, j, k, x, y, s = 0;
scanf("%d%d", &x, &y);
ar[0] = y;
ar[1] = y;
ar[2] = y;
while (1) {
if (ar[0] == x && ar[1] == x && ar[2] == x) break;
s++;
sort(ar, ar + 3);
n = ar[1] + ar[2] - 1;
if (n <= x)
ar[0] = n;
else
ar[0] = x;
}
printf("%d\n", s);
}
| 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 he{
static int min(int a,int b){
return (a<b)?a:b;
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int x,y,z;int a;
a = s.nextInt();
x = s.nextInt();
y = z = x;
int c = 0;
while(x<a || y<a || z<a){
if(x<y && x<z){
x = min(y+z-1,a);
}
else if(y<=x && y<z){
y = min(x+z-1,a);
}
else{
z = min(x+y-1,a);
}
c++;
}
System.out.print(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 | x, y = map(int, input().split())
temp = [y]*3
k = y
cnt = 0
while k != x:
temp.sort()
temp[0] = min(temp[1]+temp[2]-1, x)
k = min(temp)
cnt += 1
print(cnt)
| PYTHON3 |
712_C. Memory and De-Evolution | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
Input
The first and only line contains two integers x and y (3 β€ y < x β€ 100 000) β the starting and ending equilateral triangle side lengths respectively.
Output
Print a single integer β the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
Note
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do <image>.
In the second sample test, Memory can do <image>.
In the third sample test, Memory can do: <image>
<image>. | 2 | 9 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int x = in.nextInt();
int y = in.nextInt();
int a[] = new int[] {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);
}
}
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 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 n;
int main() {
int x, y;
scanf("%d %d", &x, &y);
int x1 = y;
int x2 = y;
int x3 = y;
int ans = 0;
while (x1 < x) {
x1 = (x2 + x3) - 1;
swap(x1, x2);
swap(x2, x3);
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.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class problemC {
static int x, y;
public static void main(String[] args) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
PrintWriter w = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(r.readLine());
x = Integer.parseInt(st.nextToken());
y = Integer.parseInt(st.nextToken());
int[] sides = {y,y,y};
int sum = 3 * y;
int answer = 0;
while (!done(sides)) {
int min = Integer.MAX_VALUE;
int index = -1;
for (int i = 0; i < 3; i++) {
if (sides[i] < min) {
min = sides[i];
index = i;
}
}
sides[index] = Math.min(x, sum - sides[index] - 1);
sum = sides[0] + sides[1] + sides[2];
answer++;
}
w.println(answer);
w.flush();
}
public static boolean done(int[] values) {
return values[0] == x && values[1] == x && values[2] == x;
}
}
| 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>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
const int N = 100001;
int main() {
int a, b, c, x, y;
cin >> x >> y;
a = b = c = y;
int ans = 0;
while (1) {
ans++;
c = a + b - 1;
y = c;
c = b;
b = a;
a = y;
if (c >= x) break;
}
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 | // package CodeForces;
import java.io.*;
import java.util.*;
public class Problem_712C {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
PrintWriter pw = new PrintWriter(System.out);
int x=sc.nextInt(),y=sc.nextInt();
int[]a=new int[3];
int min=Integer.MAX_VALUE;
// Arrays.fill(a, x);
// while(a[0]>y)
// {
// a[0]--;int c=1;
// int[]a1=a.clone();
// while(a1[2]>y)
// {
// System.out.println(Arrays.toString(a1));
// int tmp=Math.max(a1[1]-a1[0]+1,y);
// a1[2]=tmp;
// Arrays.sort(a1);
// c++;
//
// }
// System.out.println(c);
// min=Math.min(c, min);
// }
int c=0;
Arrays.fill(a, y);
while(a[0]<x)
{
a[0]=a[1]+a[2]-1;
Arrays.sort(a);
c++;
}
System.out.println(c);
pw.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
String nextLine() throws IOException {
return br.readLine();
}
boolean hasnext() throws IOException {
return br.ready();
}
}
}
| JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.