约数相关:约数个数
作者:互联网
N=(p1c1)*(p2c2)...(pk^ck)
N2=(p1(c1**2)) * (p2^ (c22) )...(pk^ (ck2) )
约数个数 f[N]=(c1+1)(c2+1)...(cn+1)
拍打牛头https://www.acwing.com/problem/content/1293/
这里没有用到公式 只是将求约数转化成为求倍数
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1000010;
int n;
int a[N], cnt[N], s[N];
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ )
{
scanf("%d", &a[i]);
cnt[a[i]] ++ ;//计数
}
for (int i = 1; i < N; i ++ )
for (int j = i; j < N; j += i)//倍数都加一遍 包括自己
s[j] += cnt[i];
for (int i = 0; i < n; i ++ ) printf("%d\n", s[a[i]] - 1);
return 0;
}
标签:约数,...,cnt,int,个数,++,相关,include 来源: https://www.cnblogs.com/liang302/p/16558235.html