题目链接:https://codeforces.com/gym/101981/attachments
Given a suqence of n integers \(a_{i}\)
Let \(mul(l, r)\) = \(\prod ^{r}_{i=1}\)and\(fac(l,r)\)be the number of distinct prime factors of\(mul(l,r)\).
Please calculate \(\sum ^{n}_{i=1}\sum ^{n}_{j=1}fac(i,j)\)
Input
The first line contains one integer \(n (1\leq n\leq 10^{6})\)— the length of the sequence.
The second line contains n integers \(a_{i} (1\leq a_{i}\leq 10^{6})\)—the sequence.
Output
Print the answer to the equation.
Examples
in:
10
99 62 10 47 53 9 83 33 15 24
out:
248
in:
10
6 7 5 5 4 9 9 1 8 12
out:
134
思路:计算每个质因子的贡献,首先从ai开始,分解质因数,记录每个质因数P出现的的位置,每个质数P的贡献是
\(n-i+(n-i)*(i-pos[P]-1)\)其中pos[p]是上一次质数出现的位置,i从0开始,n是总数,若P是第一次出现则贡献是\(n-i+(n-i)i\)
n-i代表的就是这个质数对后面的所有数都有贡献,然后\((n-i)*(i-pos[P]-1)\)代表的是这个质数从当前位置到pos[P]是新出现的,所以前面没有计算它要加上它。
当时在赛场上,死活没调对,还是太菜了
AC代码:
1 |
|