Official
A - Divisible Editorial by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
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: