In: Computer Science
Please answer in C++
Given 3 numbers T, r and s, where r != s and r > 1 & s > 1. Print a list of numbers from 1 to T where numbers divisible by r whose decimal representation does not contain the digit r should be replaced by the number 555 and any number (int) divisible by s whose decimal representation does not contain the number s should be replaced by the number 333. Numbers for which both of the past arguments are true should be replaced by the number 444.
Input
7 2 3
Expected Output
1 2 3 555 5 444 7
CODE:
#include<bits/stdc++.h>
using namespace std;
int main() {
int t,r,s,i = 1;
cin >> t >>
r >> s;
while(i <= t) {
if(i%s == 0 && i%r == 0){
cout << 444 << " ";
}else if(i%s == 0 && i != s) {
cout << 333 << " ";
}else if(i%r == 0 && i != r) {
cout << 555 << " ";
}else {
cout << i << " ";
}
i++;
}
cout <<
endl;
return 0;
}