Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <queue>
- #include <list>
- #include <stack>
- using namespace std;
- typedef vector<int> VE;
- vector<bool> VB;
- int n,m;
- bool valid(int &nombre,const VE& divisor,int m,int j){
- nombre = nombre*10 + j;
- for(int k = 0; k < m; ++k){
- if((nombre%divisor[k]) == 0) return false;
- }
- return true;
- }
- void f(int i,int nombre,const VE& divisor,int n,int m){
- if(i == n){
- cout << nombre << endl;
- }
- for(int j = 0; j < 10; ++j){
- if(valid(nombre,divisor,m,j)){
- f(i + 1,nombre,divisor,n,m);
- }
- }
- }
- int main(){
- int n;
- while(cin >> n){
- int m;
- cin >> m;
- int nombre = 0;
- VE divisor = VE(m);
- for(int k = 0; k < m; ++k){
- int num;
- cin >> num;
- divisor[k] = num;
- }
- f(0,nombre,divisor,n,m);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement