GCD vs LCM solution codeforces

GCD vs LCM solution codeforces You are given a positive integer nn. You have to find 44 positive integers a,b,c,da,b,c,d such that a+b+c+d=na+b+c+d=n, and gcd(a,b)=lcm(c,d)gcd(a,b)=lcm⁡(c,d). If there are several possible answers you can output any of them. It is possible to show that the answer always exists. In this problem gcd(a,b)gcd(a,b) denotes the greatest common divisor of aa and bb, and lcm(c,d)lcm⁡(c,d) denotes the least common multiple of cc and dd. Input The input consists … Read more

MinimizOR solution codeforces

MinimizOR solution codeforces   You are given an array aa of nn non-negative integers, numbered from 11 to nn. Let’s define the cost of the array aa as mini≠jai|ajmini≠jai|aj, where || denotes the bitwise OR operation. There are qq queries. For each query you are given two integers ll and rr (l<rl<r). For each query you should find the cost of the subarray al,al+1,…,aral,al+1,…,ar. Input Each test case consists of several test cases. The first line contains … Read more

Array Cloning Technique solution codeforces

Array Cloning Technique solution codeforces   You are given an array aa of nn integers. Initially there is only one copy of the given array. You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elements from any two copies (maybe in the same copy) … Read more

Tree Infection solution codeforces

Tree Infection solution codeforces   A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex vv (different from root) is the previous to vv vertex on the shortest path from the root to the vertex vv. Children of the vertex vv are all vertices for which vv is the parent. You … Read more

GCD Guess solution codeforces

GCD Guess solution codeforces   This is an interactive problem. There is a positive integer 1≤x≤1091≤x≤109 that you have to guess. In one query you can choose two positive integers a≠ba≠b. As an answer to this query you will get gcd(x+a,x+b)gcd(x+a,x+b), where gcd(n,m)gcd(n,m) is the greatest common divisor of the numbers nn and mm. To guess one hidden number xx you are allowed to make no more than 3030 queries. … Read more

MinimizOR solution codechef

MinimizOR solution codechef   You are given an array aa of nn non-negative integers, numbered from 11 to nn. Let’s define the cost of the array aa as mini≠jai|ajmini≠jai|aj, where || denotes the bitwise OR operation. There are qq queries. For each query you are given two integers ll and rr (l<rl<r). For each query you should find the cost of the subarray al,al+1,…,aral,al+1,…,ar. Input Each test case consists of several test cases. The first line contains … Read more

GCD Guess solution codechef

GCD Guess solution codechef   This is an interactive problem. There is a positive integer 1≤x≤1091≤x≤109 that you have to guess. In one query you can choose two positive integers a≠ba≠b. As an answer to this query you will get gcd(x+a,x+b)gcd(x+a,x+b), where gcd(n,m)gcd(n,m) is the greatest common divisor of the numbers nn and mm. To guess one hidden number xx you are allowed to make no more than 3030 queries. … Read more

Tree Infection solution codechef

Tree Infection solution codechef   A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. The parent of a vertex vv (different from root) is the previous to vv vertex on the shortest path from the root to the vertex vv. Children of the vertex vv are all vertices for which vv is the parent. You … Read more

Array Cloning Technique solution codechef

Array Cloning Technique solution codechef   You are given an array aa of nn integers. Initially there is only one copy of the given array. You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elements from any two copies (maybe in the same copy) … Read more