码迷,mamicode.com
首页 > 其他好文 > 详细

Bzoj 4146: [AMPPZ2014]Divisors

时间:2019-01-13 18:05:14      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:stream   clu   log   amp   ios   putchar   cond   span   string   

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

标签:stream   clu   log   amp   ios   putchar   cond   span   string   

原文地址:https://www.cnblogs.com/gzygzy/p/10263209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!