Official

A - Divisible Editorial by en_translator


For beginners

This problem asks to determine if an integer is a multiple of \(K\) an appropriately use an array.

To determine if \(A_i\) is a multiple of \(K\), one can divide \(A_i\) by \(K\) and check if the remainder is \(0\).

In most programming languages, one can find the remainder using % operator. See also the sample code.

Sample code (C++):

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k ;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> b;
    for(int i = 0; i < n; i++){
        if(a[i] % k == 0) b.push_back(a[i] / k);
    }
    for(int i = 0; i < b.size(); i++) cout<<b[i] << " ";
    cout << endl;
}

posted:
last update: