Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- //tries all permutations
- int main(){
- vector<int> v;
- for(int i=1;i<10;i++)
- v.push_back(i);
- while(next_permutation(v.begin(),v.end())){
- long long tmp=0;
- for(int i=0;i<10;i++){
- tmp*=10, tmp+=v[i];
- if(tmp%(i+1))break;//not divisible
- if(i>=9){//works
- for(int x:v)cout<<x<<" ";
- cout<<endl;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment