Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #define rep(i,n) for(int i=0;i<n;++i)
- using namespace std;
- template<class T> void p(T a){cout << a << endl;}
- template<class T> void pp(T &a,int p){rep(i,p)cout << a[i] <<" ";cout << endl;}
- long long int ans = 0;
- void solve(vector<int> &dg, int n, int ps[]){
- if(dg[0] == 0) return;
- rep(i,7){
- if ((dg[1+i] * 100 + dg[2+i] * 10 + dg[3+i]) % ps[i] != 0) return;
- }
- rep(i,10){
- ans += dg[9-i] * pow(10.0, i);
- }
- }
- int main(){
- int ps[] = {2, 3, 5, 7, 11, 13, 17};
- vector<int> dg;
- int n = 10;
- for(int i=0; i<10; i++) dg.push_back(i);
- do {
- solve(dg, n, ps);
- } while (next_permutation(dg.begin(), dg.end()));
- p(ans);
- return 0;
- }
Add Comment
Please, Sign In to add comment