Bzoj 4146: [AMPPZ2014]Divisors
阿新 • • 發佈:2019-01-13
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; }