- 2023tyoi0292 的博客
pow
- 2024-4-27 7:43:50 @
pow
好像还真是火题
思路:先找数中最大的平方数,但是要特判看是不是为0,如果不是就看又没有相同的数,有的话就加上数量和0的数量
AC code:
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;
int a[200005];
map<int, int> mp;
int main() {
freopen("pow.in", "r", stdin);
freopen("pow.out", "w", stdout);
int n, sum = 0, cnt0 = 0;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
for(int j = sqrt(a[i]); j >= 1; j--) {
if(a[i] % (j * j) == 0) {
a[i] /= (j * j);
break;
}
}
if(a[i] != 0) {
sum += mp[a[i]] + cnt0;
mp[a[i]]++;
}
else {
sum += i - 1;
cnt0++;
}
}
cout << sum << endl;
return 0;
}