捞
  • 板块灌水区
  • 楼主lutaoquan2012
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/7/12 10:15
  • 上次更新2024/7/12 11:24:59
查看原帖
捞
952033
lutaoquan2012楼主2024/7/12 10:15

套娃?

问题

//
// Created by 55062 on 2024/7/9.
//
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
ll T,n,x,y,ans;
map<ll,ll> mp;
int main() {
    cin>>T;
    while(T--){
        cin>>n;
        mp.clear();
        for(int i=1;i<=n;i++){
            cin>>x;
            mp[x]++;
        }ans=0;
        for(auto it:mp){
            if(it.second>=3) ans+=it.second*(it.second-1)*(it.second-2);//统计公比为1的等比数列
            for(int i=1;i*i<it.first;i++){
                //x代表a[i],it.first代表a[j],y代表a[k]
                if(i!=1&&it.first%i==0){//把i当公差
                    x=it.first/i,y=it.first*i;
                    if(mp.count(x)!=0&&mp.count(y)!=0) ans+=mp[x]*mp[y]*it.second;
                }if(it.first%i==0){//把it.first/i当公差
                    x=i,y=it.first/i*it.first;
                    if(mp.count(x)!=0&&mp.count(y)!=0) ans+=mp[x]*mp[y]*it.second;
                }
            }if(sqrt(it.first)*sqrt(it.first)==it.first&&sqrt(it.first)!=1){
                x=sqrt(it.first),y=it.first/x*it.first;
                if(mp.count(x)!=0&&mp.count(y)!=0) ans+=mp[x]*mp[y]*it.second;
            }
        }cout<<ans<<endl;
    }
    return 0;
}
2024/7/12 10:15
加载中...