Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- #define el endl
- #define umi unordered_map<int, int>
- #define umll unordered_map<ll, ll>
- #define all(vect) vect.begin(), vect.end()
- #define reset(A) memset(A, 0, sizeof(A))
- #define approx(n) fixed << setprecision(n)
- using namespace std;
- const int mod = 1e9 + 7;
- void solve()
- {
- ll n, k;
- cin >> n >> k;
- ll a[n];
- ll dp[n + 5];
- reset(dp);
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- if (a[i] == k)
- dp[i] = 1;
- }
- if (a[0] % k == 0)
- dp[0] = 1;
- for (int i = 1; i < n; i++)
- {
- if (__gcd(a[i], a[i - 1]) == k)
- {
- dp[i] = dp[i - 1] + 1;
- }
- else
- {
- dp[i] = max(dp[i], dp[i - 1]);
- }
- }
- // for (int i = 0; i < n; i++)
- // {
- // cout << dp[i] << " ";
- // }
- // cout << el;
- if(dp[n - 1] == 0) {
- cout << -1 << el;
- return;
- }
- cout << dp[n - 1] << el;
- }
- int main()
- {
- int t = 1;
- cin >> t;
- // cin.ignore();
- while (t--)
- {
- solve();
- }
- return 0;
- }
- /*
- 3
- 8 3
- 6 9 7 10 12 24 36 27
- 4 3
- 2 4 6 8
- 4 6
- 1 2 3 6
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement