Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * author: compounding
- * created: 2024-11-12 22:06:32
- **/
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- typedef vector<bool> vb;
- typedef vector<vi> vvi;
- typedef vector<pair<int, int>> vpi;
- #define f first
- #define s second
- #define yes cout << "YES" << endl
- #define no cout << "NO" << endl
- #define endl "\n"
- const int mod = 1000000007;
- int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
- int smallprime(int n)
- {
- for (int i = 2; i * i <= n; i++)
- {
- if (n % i == 0)
- {
- return i;
- }
- }
- return n;
- }
- void solve()
- {
- int n, k;
- cin >> n >> k;
- vi v(n);
- int commongcd = 0;
- for (int i = 0; i < n; i++)
- {
- cin >> v[i];
- commongcd = gcd(commongcd, v[i]);
- }
- // now we want largest l such that l divides all and l <= k
- // TODO: idea is that, we find the smallest prime number which divides the gcd, and try to get close to l
- // we choose the smallest prime divisor of GCD to get as close as possible to k
- int smallestprime = smallprime(commongcd);
- int l = smallestprime * (k / smallestprime);
- cout << l << endl;
- return;
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment