SMPDIV - Divisibility
#simple-math #ad-hoc-1 #basics
The link for the problem SMPDIV - Divisibility:
put
First, you are given t (t<100) - the number of test cases. In each of the following t lines, 3 integers: n x y.
You might assume also that x < n and x is not divisible by y.
Output
In each of the following t lines, numbers requested in the problem description in the separated by a single space in ascending order.
Example
Input: 2 7 2 4 35 5 12 Output: 2 6 5 10 15 20 25 30
The CPP solution for this problem SMPDIV - Divisibility is:
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { long long int t,i,j,k,n,a,b; cin>>t; for(long int ii=0;ii<t;ii++) { cin>>n; cin>>a>>b; for(i=1;i<n;i++) { if(i%a==0&&i%b!=0) { cout<<i<<" "; } } cout<<endl; } return 0; }
No comments:
Post a comment