Блог пользователя vedantsharma2508

Автор vedantsharma2508, история, 4 месяца назад, По-английски

The problem statement here is https://mirror.codeforces.com/contest/1535/problem/B

#include<bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        int ans = 0;
        cin >> n;
        int a[n+5];
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }

        for (int i = 1; i <= n; i++) {
            for (int j = i+1; j <= n; j++) {
                if (__gcd(a[i], a[j]*2) + __gcd(a[i]*2, a[j]) > 2) ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

I can't understand why this is an accepted solution.

Even when here we are counting two times 1) gcd(2*a[j],a[i]) 2) gcd(2*a[i],a[j])

Answer should have been something else.

In other words what is the need to see the two times the gcd ??

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

It's just very fancy way to say is this pair good or no. Because if it's not both gcds will be 1 and no matter how we place them in array result wouldn't change.