Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <queue>
  4. #include <list>
  5. #include <stack>
  6. using namespace std;
  7. typedef vector<int> VE;
  8. vector<bool> VB;
  9. int n,m;
  10.  
  11. bool valid(int &nombre,const VE& divisor,int m,int j){
  12. nombre = nombre*10 + j;
  13. for(int k = 0; k < m; ++k){
  14. if((nombre%divisor[k]) == 0) return false;
  15.  
  16. }
  17. return true;
  18. }
  19.  
  20. void f(int i,int nombre,const VE& divisor,int n,int m){
  21. if(i == n){
  22. cout << nombre << endl;
  23. }
  24. for(int j = 0; j < 10; ++j){
  25. if(valid(nombre,divisor,m,j)){
  26. f(i + 1,nombre,divisor,n,m);
  27. }
  28. }
  29. }
  30.  
  31. int main(){
  32. int n;
  33. while(cin >> n){
  34. int m;
  35. cin >> m;
  36. int nombre = 0;
  37. VE divisor = VE(m);
  38. for(int k = 0; k < m; ++k){
  39. int num;
  40. cin >> num;
  41. divisor[k] = num;
  42. }
  43. f(0,nombre,divisor,n,m);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement