1029: Observer-Enhanced Edition time limit: 1 Sec Memory Limit: MB
Title Description
The final exam of the Academy of Witchcraft and Wizardry began.
The headmaster Jacobi used magic to create an observer in the examination room to observe the situation of the examination room.
The entire examination room can be regarded as a xoy plane, the coordinates of the n*n candidates are (p,q) (1<=p,q<=n, p,q∈z+), and the observer coordinates are (0,0).
But the problem is, even in the ideal case of abstracting the examinee into a point, the Jacobi Observer does not see all the candidates ' movements, because some of the candidates are obscured by other candidates. To see the masked candidate, Jacobi added Magic "Mana preception" to the Observer. Now the observer can successfully see all the candidates, but see that a candidate needs to consume the magic of Jacobi (the number of candidates + 1) that the viewer and the examinee have wired through.
Now Jacobi wants to know how much magic he needs to consume if his observer is able to monitor the entire exam.
Input
The first line of the input file watcher.in contains a positive integer n.
Output
The output file Watcher.out contains a positive integer meaning the problem description.
Sample input
3
Sample output
12
Tips
[Data size]
For 40% of data: n<=1000.
For 80% of data: n<=1000000.
For 100% of data: 1<=n<=10000000.
[Precautions]
The length of the code must not exceed 2KB.
Exercises
Hey, Ysy still better than me ah, we asked the next cyh to launch.
This topic is Möbius inversion.
The derivation process is shown above
We enumerate D, and the complexity is O (n)
The front can be pre-processed drip.
The main thing is, the last one can be pretreated, I how to multiply it? You can sum it with arithmetic progression.
Because for each piece of the back of a lump of things, except I are unchanged, then the proposed for a bit OK.
1#include <stdio.h>2#include <iostream>3 using namespacestd;4 intmu[10000001];5 intN;6 intzs[10000001];7 intprime[1000001],tot;8 Long Longans=0;9 intf[10000001];Ten intMain () { Onescanf"%d",&n); A for(intI=2; i<=n;++i) { - if(!Zs[i]) { -zs[i]=i; theprime[++tot]=i; - } - for(intj=1; j<=tot&&i*prime[j]<=n;++j) { -zs[i*prime[j]]=Prime[j]; + if(i%prime[j]==0) Break; - } + } Af[1]=1; at for(intI=2; i<=n;++i)if(Zs[i/zs[i]]!=zs[i]) f[i]=f[i/zs[i]]*-1; - intLast1; - for(intI=1; i<=n;i=last1+1) { -last1=n/(n/i); - for(intR=I;R<LAST1;++R) f[last1]+=F[r]; - if(f[last1]!=0) { in Long Longsum=0; - intlast2=n/i; to intLast3; + for(intj=1; j<=last2;j=last3+1) { -last3=last2/(last2/j); thesum+= (Long Long) (last2/j) * (last2/j) * (J+LAST3) * (last3-j+1)/2; * } $ans+=sum*F[last1];Panax Notoginseng } - } theprintf"%lld\n", ans); + return 0; A}
View Code
[FZSZOJ 1029] Observer-Enhanced Edition