Codeforces 1541B - Pleasant Pairs Solution



///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long  t,n,i,j,a,c;
    pair<long long,long long>p[100009];
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(i=1; i<=n; i++)
        {
            cin>>a;
            p[i]= {a,i};
        }
        c=0;
        sort(p+1,p+1+n);
        for(i=1;i<=n;i++)
        {
            for(j=i+1;j<=n;j++)
            {
                if((p[i].first*p[j].first)>n+n)
                    break;
                else
                {
                    if((p[i].first*p[j].first)==p[i].second+p[j].second)
                        c++;
                }
            }
        }
        cout<<c<<endl;
    }
    return 0;
}


No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.