January 2022

B - Raingirl Likes Even Powers

Solution

\[\]

Implementation in C++

#include <bits/stdc++.h>

using namespace std;

int main() {
    int t, n, k, x;
    cin>>t;
    
    while (t--) {
        cin>>n>>k;
        
        x = 0;
        
        while (n >= k) {
            n /= k;
            x++;
        }
        
        if (x%2 == 0)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
    
    return 0;
}
\[\]

Implementation in Java

import java.io.*;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        int t, n, k, x;
        t = scan.nextInt();
        
        while (t-- > 0) {
            n = scan.nextInt();
            k = scan.nextInt();
            
            x = 0;
            
            while (n >= k) {
                n /= k;
                x++;
            }
            
            if (x%2 == 0)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}
\[\]

Implementation in Python

t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    x = 0
    
    while n >= k:
        x += 1
        n //= k
        
    if x%2 == 0:
        print('YES')
    else:
        print('NO')
\[\]

Contest Material