Bzoj 4146: [AMPPZ2014]Divisors

Posted gzygzy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Bzoj 4146: [AMPPZ2014]Divisors相关的知识,希望对你有一定的参考价值。

Bzoj 4146: [AMPPZ2014]Divisors

暴力剪枝题目

直接枚举倍数.(调和级数

发现过不了的话,就将重复的数合到一起.

时间复杂度(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的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ 4144: [AMPPZ2014]Petrol

BZOJ 4148 4148: [AMPPZ2014]Pillars (乱搞)

BZOJ4147: [AMPPZ2014]Euclidean Nim

bzoj4152[AMPPZ2014]The Captain 最短路

Bzoj 4145: [AMPPZ2014]The Prices

bzoj4152[AMPPZ2014]The Captain*