标签:stream clu log amp ios putchar cond span string
暴力剪枝题目
直接枚举倍数.(调和级数
发现过不了的话,就将重复的数合到一起.
时间复杂度\(O(n log n)\)
/*header*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i , x, p) for(register int i = x;i <= p;++ i)
#define sep(i , x, p) for(int i = x;i >= p;-- i)
#define gc getchar()
#define pc putchar
#define ll long long
#define mk make_pair
#define fi first
#define se second
using std::min;
using std::max;
using std::swap;
inline int gi() {
int x = 0,f = 1;char c = gc;
while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}return x * f;
}
void print(int x) {
if(x < 0) pc('-') , x = -x;
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxN = 2000000 + 7;
int a[maxN] , num[maxN] , b[maxN], tot;
ll ans;
int main() {
int n = gi();
rep(i , 1, n) {
a[i] = gi() , num[a[i]] ++;
if(num[a[i]] == 1) b[++ tot] = a[i];
}
rep(i , 1, tot) {
for(register int j = b[i];j <= 2000000;j += b[i]) {
ans += (long long)num[b[i]] * num[j];
}
ans -= num[b[i]];
}
printf("%lld",ans);
return 0;
}
Bzoj 4146: [AMPPZ2014]Divisors
标签:stream clu log amp ios putchar cond span string
原文地址:https://www.cnblogs.com/gzygzy/p/10263209.html