Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define x first
- #define y second
- #define mp make_pair
- #define pb push_back
- #define sqr(a) ((a) * (a))
- #define sz(a) int(a.size())
- #define all(a) a.begin(), a.end()
- #define forn(i, n) for(int i = 0; i < int(n); i++)
- #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
- typedef long long li;
- typedef long double ld;
- typedef pair<int, int> pt;
- template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
- return out << "(" << a.x << ", " << a.y << ")";
- }
- template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
- out << "[";
- forn(i, sz(v)) {
- if(i) out << ", ";
- out << v[i];
- }
- return out << "]";
- }
- mt19937 rnd(time(NULL));
- const int INF = int(1e9);
- const li INF64 = li(1e18);
- const int MOD = INF + 7;
- const ld EPS = 1e-9;
- const ld PI = acos(-1.0);
- li x;
- bool read () {
- if (!(cin >> x))
- return false;
- return true;
- }
- void solve() {
- vector<int> nz, d;
- while (x){
- if (x % 10) nz.pb(x % 10);
- d.pb(x % 10);
- x /= 10;
- }
- int cnt = 0;
- while ((cnt & 1023) || (clock() < 240)){
- ++cnt;
- int f = nz[rnd() % sz(nz)];
- li num = f;
- d.erase(find(all(d), f));
- shuffle(all(d), rnd);
- forn(i, sz(d))
- num = num * 10 + d[i];
- if (num % 17 == 0){
- printf("%lld\n", num);
- return;
- }
- d.pb(f);
- }
- puts("-1");
- }
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- int tt = clock();
- #endif
- cerr.precision(15);
- cout.precision(15);
- cerr << fixed;
- cout << fixed;
- while(read()) {
- solve();
- #ifdef _DEBUG
- cerr << "TIME = " << clock() - tt << endl;
- tt = clock();
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement