本文主要是介绍xay loves count,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题目链接:
题解:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e6;
int a[maxn+5],b[maxn+5];
signed main(){int n,ans=0,s1=0;scanf("%lld",&n);for (int i = 0; i < n; ++i) {int x;scanf("%lld",&x);b[x]++;if(x==1) s1++;}ans=ans+s1*s1*s1;for (int i = 2; i <= maxn; ++i) {if(b[i]) ans=ans+s1*b[i]*b[i]*2;}for (int i = 2; i <= 1000; ++i) {if(b[i]) {for (int j = i; j * i <= maxn; ++j) {if (j == i && b[i * j]) ans = ans + b[i] * b[i] * b[i * j];else if (j != i && b[j] && b[i * j])ans = ans + b[i] * b[j] * 2 * b[i * j];}}}printf("%lld\n",ans);return 0;
}
这篇关于xay loves count的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!