Bzoj 2154 The inverse of the LCM and

Source: Internet
Author: User

Main topic:

The value of each position (I,J) in the table is the LCM (I,J), which is the size of the N*m table value.

This paper Jia Zhipeng the process of linear sieve is very good.

The last inverse of the equation, I'm using Euler's theorem.

I have this last linear sweep over, barely over, efficiency is not very high ...

1 /*Bzoj 2154*/2#include <bits/stdc++.h>3 4 using namespacestd;5 #definell Long Long6 #defineN 100000007 Const intMOD =20101009;8 intmu[n+5], prime[n+5], f[n+5], tot;9 BOOLcheck[n+5];Ten  One voidInit () A { -mu[1] =1, f[1] =1; -      for(intI=2; I<=n; i++){ the         if(!Check[i]) { -prime[tot++] =i; -Mu[i] =-1; -F[i] =1-i; +         } -          for(intj=0; J<tot; J + +){ +             if(LL) prime[j]*i>n) Break; ACheck[prime[j]*i] =true; at             if(i%Prime[j]) { -Mu[prime[j]*i] =-Mu[i]; -F[prime[j]*i] = ((ll) f[prime[j]]*f[i])%MOD; -}Else{ -F[prime[j]*i] =F[i]; -                  Break; in             } -         } to     } + } -  the intQ_pow (intb) * { $ll ans =1, a=4;Panax Notoginseng      while(b) -     { the         if(b&1) ans = (ans*a)%MOD; +A = (a*a)%MOD; Ab>>=1; the     } +     return(int) ans; - } $  $ intSolveintNintm) - { -     if(n>m) Swap (n, m); theLL ret =0; -      for(intk=1; K<=n; k++){Wuyill a = n/k, B = m/K; theret = (ret+ (k* (1+a)%mod) *a%mod*b%mod* (1+b)%mod*f[k]%mod)%MOD; -     } Wuret = (ll) Ret*q_pow (mod-2)%mod+mod)%MOD; -     return(int) ret; About } $  - intMain () - { -   //freopen ("In.txt", "R", stdin); A init (); +     intN, M; the    /*for (int i=2; i<=100000; i++) - if (!check[i] && mod%i==0) cout<<i<< "yes" <<endl;*/ $      while(~SCANF ("%d%d", &n, &m)) { theprintf"%d\n", Solve (n, m)); the     } the     return 0; the}

Bzoj 2154 Inverse of the LCM and

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.