Check if two piles of coins can be emptied by repeatedly removing 2 coins from a pile and 1 coin from the other | C ++ program for the above approach ; Function to check if two given piles can be emptied by repeatedly removing 2 coins from a pile and 1 coin from the other ; If maximum of A & B exceeds the twice of minimum of A & B ; Not possible to empty the piles ; If sum of both the coins is divisible by 3 , then print Yes ; Otherwise , print " No " ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void canBeEmptied ( int A , int B ) { if ( max ( A , B ) > 2 * min ( A , B ) ) { cout << " No " ; return ; } if ( ( A + B ) % 3 == 0 ) cout << " Yes " ; else cout << " No " ; } int main ( ) { int A = 1 , B = 2 ; canBeEmptied ( A , B ) ; return 0 ; }