bzoj 4146: [AMPPZ2014]Divisors 暴力
2017-07-20 10:09
204 查看
题意
给定一个序列a[1],a[2],…,a。求满足i!=j且a[i]|a[j]的二元组(i,j)的个数。
1<=n<=2000000,1<=a[i]<=2000000
分析
暴力找即可。代码
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int N=2000005; int n,s ; int main() { scanf("%d",&n); int mx=0; for (int i=1;i<=n;i++) { int x; scanf("%d",&x); s[x]++;mx=max(mx,x); } LL ans=0; for (int i=mx;i>=1;i--) if (s[i]) { ans+=(LL)s[i]*(s[i]-1); for (int j=i*2;j<=mx;j+=i) ans+=(LL)s[i]*s[j]; } printf("%lld",ans); return 0; }
相关文章推荐
- 4146: [AMPPZ2014]Divisors
- BZOJ 4145: [AMPPZ2014]The Prices( 状压dp + 01背包 )
- 【BZOJ 4148】 4148: [AMPPZ2014]Pillars (乱搞)
- 【BZOJ】【4146】 【AMPPZ2014】Divisors
- BZOJ 4145: [AMPPZ2014]The Prices
- 循环队列+堆优化dijkstra最短路 BZOJ 4152: [AMPPZ2014]The Captain
- BZOJ 4144: [AMPPZ2014]Petrol 最短路+最小生成树+倍增
- BZOJ 4143: [AMPPZ2014]The Lawyer( sort )
- bzoj 4145: [AMPPZ2014]The Prices 状压dp
- 【bzoj4146】[AMPPZ2014]Divisors
- BZOJ 4152: [AMPPZ2014]The Captain 题解 【贪心】【SPFA】
- BZOJ 4152: [AMPPZ2014]The Captain( 最短路 )
- bzoj 4144: [AMPPZ2014]Petrol spfa+最小生成树
- BZOJ 4152: [AMPPZ2014]The Captain 分层图最短路
- bzoj 4152: [AMPPZ2014]The Captain
- bzoj 4144: [AMPPZ2014]Petrol
- bzoj4146 [AMPPZ2014]Divisors
- 【AMPPZ2014】【BZOJ4146】Divisors
- [BZOJ]4151: [AMPPZ2014]The Cave
- 【BZOJ4146】[AMPPZ2014]Divisors