Möbius multiply 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.