math number theory

Please click on ads to support us..

Python Code:

from sys import stdin

input = stdin.readline



def ii():
    return int(input())


def li():
    return list(map(int, input().split()))


from math import sqrt


def perfect_sq(n):
    x = int(sqrt(n))

    while x * x < n:
        x += 1

    while x * x > n:
        x -= 1

    return (x * x == n)

for _ in range(ii()):
    a,b,c,d=li()
    if a*d == b*c:
        print(0)
        continue

    if a==0 or c==0:
        print(1)
        continue

    if (a*d) % (b*c) == 0 or (b*c) % (a*d) == 0:
        print(1)
    else:
        print(2)

C++ Code:

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define ld long double
using namespace std;
int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}
signed main() {
    int t;
    cin >> t;
    while(t--)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        if(a*d == b*c) { cout << 0 << endl; continue; }
        int x = a*d, y = b*c;
        int r = gcd(x, y);
        if(r != x and r != y) cout << 2 << endl;
        else cout << 1 << endl;
        
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II