Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int> getPrimeFactors(int a, vector<int> & primes)
- {
- vector<int> f;
- for (auto p : primes)
- {
- if (p > a) break;
- if (a % p == 0)
- {
- f.push_back(p);
- do
- {
- a /= p;
- } while (a % p == 0);
- }
- }
- if (a > 1) f.push_back(a);
- return f;
- }
- void solution(vector<int> & A, vector<int> & B)
- {
- vector<int> primes;
- primes.push_back(2);
- for (int i = 3; i * i <= 1e9; ++i)
- {
- bool isPrime = true;
- for (auto p : primes)
- {
- if (i % p == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime)
- {
- primes.push_back(i);
- }
- }
- int N = A.size();
- map<int, int> cntp;
- for (int i = 0; i < N; i++)
- {
- auto f = getPrimeFactors(A[i], primes);
- vector<pair<int, int>> x;
- x.push_back({ 0, 1 });
- for (auto p : f)
- {
- int k = x.size();
- for (int i = 0; i < k; ++i)
- {
- int nn = x[i].first + 1;
- int pp = x[i].second * p;
- ++cntp[pp];
- x.push_back({ nn, pp });
- }
- }
- }
- int cnt = N; cnt *= N;
- for (int i = 0; i < N; i++)
- {
- auto f = getPrimeFactors(B[i], primes);
- vector<pair<int, int>> x;
- x.push_back({ 0, 1 });
- for (auto p : f)
- {
- int k = x.size();
- for (int i = 0; i < k; ++i)
- {
- int nn = x[i].first + 1;
- int64_t pp = x[i].second * p;
- x.push_back({ nn, pp });
- if (nn % 2 == 1)
- {
- cnt -= cntp[pp];
- }
- else
- {
- cnt += cntp[pp];
- }
- }
- }
- }
- int temp = A.size() * A.size();
- cout << temp - cnt << endl;
- }
- int main()
- {
- int n; cin >> n;
- vector<int> a(n), b(n);
- for (int i = 0; i < n; i++) cin >> a[i];
- for (int i = 0; i < n; i++) cin >> b[i];
- solution(a, b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement