Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "MAXPRIME"
- #include <iostream>
- #include <cstdio>
- #include <vector>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 1e5 + 5;
- string s;
- void Read()
- {
- cin >> s;
- }
- // String to Integer
- ll toi(const string &s)
- {
- ll ans(0);
- for (auto i : s)
- ans = ans * 10 + i - '0';
- return ans;
- }
- bool IsPrime(ll v)
- {
- if (v == 1)
- return false;
- if (v % 2 == 0) // Số chẵn
- return v == 2;
- for (int i = 3; 1ll * i * i <= v; i += 2)
- if (v % i == 0)
- return false;
- return true;
- }
- void Solve()
- {
- vector<int> p;
- for (int i = 0; i < (int)s.size(); ++i)
- if (s[i] == '?')
- p.emplace_back(i);
- string ans;
- for (int i = 1; i < 10; ++i)
- for (int j = 1; j < 10; ++j)
- {
- s[p[0]] = i + '0';
- s[p[1]] = j + '0';
- if (IsPrime(toi(s)))
- ans = max(ans, s);
- }
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement