Solutions
CodeChef
CodeChef
  • Home
  • Compete
    • April Long One 2022
Powered by GitBook
On this page
  • Ezio and Guards
  • The Cooler Dilemma 1
  • The Cooler Dilemma 2
  • Dazzling GCD Pair
  • Dazzling AXNODR Challenge
  • Prime Sum
  • Pairwise Xors

Was this helpful?

  1. Compete

April Long One 2022

PreviousHome

Last updated 2 years ago

Was this helpful?

Ezio and Guards

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        int x, y;
        cin >> x >> y;
        if (x >= y) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}
public static void Main() {
    int testcases = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < testcases; i++) {
        // your code goes here
        string[] inputs = Console.ReadLine().Split();
        int x = int.Parse(inputs[0]);
        int y = int.Parse(inputs[1]);
        if (x >= y)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

The Cooler Dilemma 1

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        int x, y, z;
        cin >> x >> y >> z;
        if (x * z < y)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}
public static void Main() {
    int testcases = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < testcases; i++) {
        // your code goes here
        string[] inputs = Console.ReadLine().Split();
        int x = int.Parse(inputs[0]);
        int y = int.Parse(inputs[1]);
        int z = int.Parse(inputs[2]);
        if (x * z < y)
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

The Cooler Dilemma 2

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        int a, b;
        cin >> a >> b;
        if (b % a == 0) {
            int p = b / a - 1;
            if (p < 0) {
                cout << 0 << endl;
            } else {
                cout << p << endl;
            }
        } else {
            int p = b / a;
            cout << p << endl;
        }
    }
    return 0;
}
public static void Main() {
    int testcases = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < testcases; i++) {
        // your code goes here
        string[] inputs = Console.ReadLine().Split();  // input
        int a = int.Parse(inputs[0]);
        int b = int.Parse(inputs[1]);
        if (b % a == 0) {
            int p = b / a - 1;
            if (p < 0)
                Console.WriteLine(0);
            else
                Console.WriteLine(p);
        } else {
            int p = b / a;
            Console.WriteLine(p);
        }
    }
}

Dazzling GCD Pair

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        long a, b, i = -1;
        cin >> a >> b;
        if (a % 2 == 0) {
            if (a + 2 <= b)
                cout << a << " " << a + 2;
            else
                cout << i;
        } else if (a % 3 == 0) {
            if (a + 3 <= b)
                cout << a << " " << a + 3;
            else
                cout << i;
        } else {
            if (a + 3 <= b)
                cout << a + 1 << " " << a + 3;
            else
                cout << i;
        }
        cout << endl;
    }
    return 0;
}
public static void Main() {
    int testcases = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < testcases; i++) {
        // your code goes here
        string[] inputs = Console.ReadLine().Split();  // input
        var a = long.Parse(inputs[0]);
        var b = long.Parse(inputs[1]);
        var result = -1;
        if (a % 2 == 0) {
            if (a + 2 <= b)
                Console.WriteLine($"{a} {a + 2}");
            else
                Console.WriteLine(result);
        } else if (a % 3 == 0) {
            if (a + 3 <= b)
                Console.WriteLine($"{a} {a + 3}");
            else
                Console.WriteLine(result);
        } else {
            if (a + 3 <= b)
                Console.WriteLine($"{a + 1} {a + 3}");
            else
                Console.WriteLine(result);
        }
    }
}

Dazzling AXNODR Challenge

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        long long n, result = 0;
        cin >> n;
        if (n % 2 == 0)  // even - bitwise XOR
        {
            if (n % 4 == 0)
                result = 3 ^ n;
            else
                result = 3;
        } else  // odd - bitwise AND
        {
            if ((n - 1) % 4 == 0)
                result = (3 ^ (n - 1)) & n;
            else
                result = 3;
        }
        cout << result << endl;
    }
    return 0;
}
public static void Main() {
    int testcases = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < testcases; i++) {
        // your code goes here
        long n = long.Parse(Console.ReadLine());
        long result = 0;
        if (n % 2 == 0) {
            if (n % 4 == 0)
                result = 3 ^ n;
            else
                result = 3;
        } else {
            if ((n - 1) % 4 == 0)
                result = (3 ^ (n - 1)) & n;
            else
                result = 3;
        }
        Console.WriteLine(result);
    }
}

Prime Sum

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        long long a, b, result;
        cin >> a >> b;
        if (a == 1 || b == 1)
            result = -1;
        else if (__gcd(a, b) == 1)
            result = 1;
        else
            result = 0;

        cout << result << endl;
    }
    return 0;
}
public static void Main() {
    int testcases = Convert.ToInt32(Console.ReadLine());
    for (int i = 0; i < testcases; i++) {
        // your code goes here
        string[] inputs = Console.ReadLine().Split();  // input
        long a = long.Parse(inputs[0]);
        long b = long.Parse(inputs[1]);
        long result;
        if (a == 1 || b == 1)
            result = -1;
        else if (GCD(a, b) == 1)
            result = 1;
        else
            result = 0;
        Console.WriteLine(result);
    }
}

public static long GCD(long a, long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

Pairwise Xors

#include <iostream>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin >> t;
    while (t--) {
        long long x;
        cin >> x;
        long long a = x & -(x - 1);
        if (x & 1 || x == a) {
            cout << -1 << endl;
        } else {
            cout << a / 2 << " " << x / 2 << " " << (x - a) / 2 << endl;
        }
    }
    return 0;
}

https://www.codechef.com/APRIL221D/problems/MANIPULATE
https://www.codechef.com/APRIL221D/problems/WATERCOOLER1
https://www.codechef.com/APRIL221D/problems/WATERCOOLER2
https://www.codechef.com/APRIL221D/problems/NOTUNIT
https://www.codechef.com/APRIL221D/problems/AXNODR
https://www.codechef.com/APRIL221D/problems/PRIMESM
https://www.codechef.com/APRIL221D/problems/XORABC