Bzoj Crash's digital table 2154
Main topic
N, M <= 10^7
Finally, the serious Möbius multiply. is to include two transformations 1. Möbius reproduction, Möbius transformation 2. Consider the contribution (number of times counted) and change the enumeration order to achieve the purpose of the linear sieve.
Because the process is too cumbersome, replace the input with a picture
Reduce the number of modulus to be miraculous, do not know why so slow
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 #defineMAXN 100000207 #defineMoD 201010098 9 intprime[maxn],cnt;Ten Long LongF[MAXN]; One BOOLTAG[MAXN]; A Long LongN,m,ans; - - voidinit () { thef[1] =1; - for(Registerinti =2; I <= N; i++){ - if(!tag[i]) prime[++cnt] = i, f[i] =1-i; - for(Registerintj =1; J <= CNT && prime[j] * i <= N; J + +){ +Tag[i * Prime[j]] =1; - if((i% prime[j]) = =0 ){ +F[i * Prime[j]] =F[i]; A Break; at } - Else{ -F[i * Prime[j]] = (f[i] * (Long Long) (1-prime[j])); - } - } - } in for(RegisterLong Longi =1; I <= N; i++) F[i] = (F[i] *i); - for(Registerinti =2; I <= N; i++) F[i] = (F[i] + f[i-1]) %MoD; to } +InlineLong LongPowerLong LongXLong Longy) { - Long Longres =1; the while(y) { * if(Y &1) Res = (res * x)%MoD; $x = (x * x)%MoD;Panax NotoginsengY >>=1; - } the returnRes%MoD; + } A intMain () { theFreopen ("Input.txt","R", stdin); +scanf"%lld%lld",&n,&m); - if(N >m) swap (n,m); $ init (); $ for(RegisterLong Longi =1; I <=min (n,m);) { - Long LongNext = Min (n/(n/i), m/(m/i)); -Ans = (ans + ((F[next]-f[i-1] + MoD)% mod * (n/i)% mod * (m/i)% mod * (n/i +1)% MoD * (m/i +1) (% MoD))%MoD; thei = next +1; - }WuyiAns = (ans * Power (4, MoD-2)) %MoD; theprintf"%d\n",(int) ((ans% mod + MoD)%MoD)); -}
Möbius multiply 1