Sort by

recency

|

63 Discussions

|

  • + 0 comments
    import java.util.Scanner;
    
    public class Solution {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    
    		int T = sc.nextInt();
    		for (int tc = 0; tc < T; tc++) {
    			int a = sc.nextInt();
    			int b = sc.nextInt();
    			int c = sc.nextInt();
    			System.out.println(solve(a, b, c));
    		}
    
    		sc.close();
    	}
    
    	static String solve(int a, int b, int c) {
    		return (c <= Math.max(a, b) && c % gcd(a, b) == 0) ? "YES" : "NO";
    	}
    
    	static int gcd(int x, int y) {
    		return (y == 0) ? x : gcd(y, x % y);
    	}
    }
    
  • + 0 comments

    def solve(a, b, c): yes, no = "YES", "NO" a, b = max(a, b), min(a, b)

    """ KAIFU KI AAWAAZ BADI MANHOOS HAI ,SUN LO TO AISA LAGEGA MANO JAISE LAKADBAGHGHE KA GALA BAITHA HAI , KAIF KI ID: 2301641530110"""

  • + 0 comments
    public static String solve(int a, int b, int c) {
    

    // char* solve(int a, int b, int c) { int c1=hcf(a,b); if(c<=Math.max(a,b)&&c%c1==0) return "YES"; else return "NO";

    } public static int hcf(int n1, int n2) { if (n2 != 0) return hcf(n2, n1 % n2); else return n1; } }

  • + 0 comments

    My Python3 solution

    def solve(a, b, c):
        yes, no = "YES", "NO"
        a, b = max(a, b), min(a, b)
    
        b_states = {0, b}
        a_states = {0, a}
        b_state = b_states.copy()
        a_state = a_states.copy()
        if c in a_states or c in b_states:
            return yes
        search = True
        while search:
            for jug_a in a_state:
                for jug_b in b_state:
                    
                    a1, a2 = min(a, jug_a + jug_b), max(0, jug_a - (b - jug_b))
                    b1, b2 = min(b, jug_b+jug_a), max(0, jug_b - (a - jug_a))
                    
                    if c in {a1, a2, b1, b2}:
                        return yes
            
                    a_states.add(a1)
                    a_states.add(a2)
                    
                    b_states.add(b1)
                    b_states.add(b2)
        
            if a_states == a_state and b_states == b_state:
                break
        
    
            b_state = b_states.copy()
            a_state = a_states.copy()
    
        # print(a_states, b_states)
        return no
    
  • + 0 comments

    I first solved this problem with backtracking (which works great for games, or procedures with limited next steps available), but using the gcd was a lot simpler - I didn't think about it for a while, though. So there are a few ways to solve this problem!