关于我所有全局都开long long了但是函数参数没开long long。。。。。
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
namespace xxy {
//#define int unsigned long long
using ull = unsigned long long;
unsigned long long a[100005], n;
const int N = (1 << 15) - 1;
unsigned long long f[1 << 17];
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int get(ull x)
{
int re = 0;
for(int i = 0; i < 15; i++) {
if(x % prime[i] == 0) {
re |= (1 << i);
}
}
return re;
}
void solve()
{
int n;
memset(f, 0, sizeof(f));
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = get(a[i]);
f[a[i]]++;
//cout << a[i] << " ";
} // cout << "" << endl;
//for(int i=0;i<(1<<3);i++){
// cout << f[i] << " ";
//}cout<<endl;
for(int i = 0; i < 15; i++) {
for(int j = 0; j < (1 << 15); j++) {
if(j & (1 << i))f[j] += f[j ^ (1 << i)];
}
}
//for(int i=0;i<(1<<3);i++){
//cout << f[i] << " ";
//}cout<<endl;
unsigned long long ans = 0;
for(int i = 1; i <= n; i++) {
int g = a[i], popcnt = 0;
for(int j = 0; j < 15; j++) {
if((1 << j) & g) {
popcnt++;
int t = g ^ (1 << j);
ans += f[t ^ N];
}
}
ans -= (popcnt - 1) * f[g ^ N];
}
cout << ans << "\n";
}
signed main()
{
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
cin.tie(0), cout.tie(0);
std::ios::sync_with_stdio(false);
// init();
int T;
cin >> T;
while(T--) {
solve();
}
return 0;
}
}
signed main()
{
return xxy::main();
}
以上为改后
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
namespace xxy {
//#define int unsigned long long
using ull = unsigned long long;
unsigned long long a[100005], n;
const int N = (1 << 15) - 1;
unsigned long long f[1 << 17];
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int get(int x)
{
int re = 0;
for(int i = 0; i < 15; i++) {
if(x % prime[i] == 0) {
re |= (1 << i);
}
}
return re;
}
void solve()
{
int n;
memset(f, 0, sizeof(f));
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = get(a[i]);
f[a[i]]++;
//cout << a[i] << " ";
} // cout << "" << endl;
//for(int i=0;i<(1<<3);i++){
// cout << f[i] << " ";
//}cout<<endl;
for(int i = 0; i < 15; i++) {
for(int j = 0; j < (1 << 15); j++) {
if(j & (1 << i))f[j] += f[j ^ (1 << i)];
}
}
//for(int i=0;i<(1<<3);i++){
//cout << f[i] << " ";
//}cout<<endl;
unsigned long long ans = 0;
for(int i = 1; i <= n; i++) {
int g = a[i], popcnt = 0;
for(int j = 0; j < 15; j++) {
if((1 << j) & g) {
popcnt++;
int t = g ^ (1 << j);
ans += f[t ^ N];
}
}
ans -= (popcnt - 1) * f[g ^ N];
}
cout << ans << "\n";
}
signed main()
{
#ifdef LOCAL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
cin.tie(0), cout.tie(0);
std::ios::sync_with_stdio(false);
// init();
int T;
cin >> T;
while(T--) {
solve();
}
return 0;
}
}
signed main()
{
return xxy::main();
}
以上为改前