ec1117

Untitled

Jun 23rd, 2021 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. //tries all permutations
  5.  
  6. int main(){
  7.     vector<int> v;
  8.     for(int i=1;i<10;i++)
  9.         v.push_back(i);
  10.     while(next_permutation(v.begin(),v.end())){
  11.         long long tmp=0;
  12.         for(int i=0;i<10;i++){
  13.             tmp*=10, tmp+=v[i];
  14.             if(tmp%(i+1))break;//not divisible
  15.             if(i>=9){//works
  16.                 for(int x:v)cout<<x<<" ";
  17.                 cout<<endl;
  18.             }
  19.         }
  20.     }
  21. }
Add Comment
Please, Sign In to add comment