Program time limit: 1 second
Program memory limit: 512 MB
At Quokkas and Koalas Love Society, your members are mingling based on how much they like Quokkas and Koalas.
Each member has a value $Q_i$ which indicates how much they like Quokkas and a value $K_i$ which indicates how much they like Koalas. Two members $i$ and $j$ have a Quokka love coefficient of $Q_i \cdot Q_j$ and a Koala love coefficient of $K_i \cdot K_j$. Two members are friends if these coefficients are equal.
Output how many pairs of friends there are.
For all test cases:
You should read from standard input and write to standard output.
In Python, you could use the following code.
# Taking inputs, already done! :D
N = int(input())
Q = list(map(int, input().split()))
K = list(map(int, input().split()))
ans = 0
# Write your code here
# Printing output
print(ans)
In C or C++, you could use the following code.
// Taking inputs, already done! :D
int N; scanf("%d", &N);
long long Q[N]; for (int i = 0; i < N; i++) scanf("%lld", &Q[i]);
long long K[N]; for (int i = 0; i < N; i++) scanf("%lld", &K[i]);
long long ans;
// Write your code here
// Printing output
printf("%lld\n", ans);
6
1 2 2 5 5 6
1 1 4 0 5 4
2
We need to find pairs $(i,j)$ where $Q_i \cdot Q_j = K_i \cdot K_j$.
For members 1 and 5, $Q_1 \cdot Q_5 = 1 \cdot 5 = 5$ and $K_1 \cdot K_5 = 1 \cdot 5 = 5$ so they are friends. For members 2 and 3, $Q_2 \cdot Q_3 = 2 \cdot 2 = 4$ and $K_2 \cdot K_3 = 1 \cdot 4 = 4$ so they are also friends. These are our only pairs of friends, so the answer is $2$.
3
2 3 0
3 2 0
3
All three pairs are friends, so the answer is $3$.
Your program will be run on both sample cases and 7 secret cases one after another, and if it produces the correct output for all test cases, it solves this task. Recall that your final score on the task is the score of your highest scoring submission.
Log in to submit!