3813: Odd Country | tree Array | Euler function

Source: Internet
Author: User

The topic is obviously asking for φ( ∏ < Span class= "Texatom" id= "mathjax-span-4164" >i = Span class= "Mi" id= "mathjax-span-4168" style= "font-size:70.7%; Font-family:mathjax_math-italic; " >l < Span class= "Texatom" id= "mathjax-span-4169" >r a i )
You can use the segment tree to maintain the product and then find the inverse of the Euler function, the method of pressure can be reduced by 60 times times the constant. Consider a tree-like array, because only - A quality factor, so you can open - A tree array maintains each quality factor, initially preserving the product of the prefix and then T flies. Because multiplication is slower than addition, you can maintain the exponent of a prefix, so that you can successfully bzoj the last page qaq, but Uoj's extra test is not(it should be the reason why I wrote the code too ugly.)

#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <vector>#include <cmath>#include <queue>#include <set>#include <map>#define LL Long Long#define MOD 19961993#define N 100001using namespace Std;intSC () {intI=0, f=1; Char C=getchar (); while(c>' 9 '|| c<' 0 '){if(c=='-') f=-1; C=getchar ();} while(c>=' 0 '&&c<=' 9 ') i=i*10+c-' 0 ', C=getchar ();returnI*f;}intprime[ the],inv[ the],b[ -],top;int TR[ A][n],n,q,a[n],flag;ll Cal (LLx, LLy) {ll ans=1; for(;y;x=x*x%mod,y>>=1)if(y&1) Ans=ans*x%mod;returnAns;} void Change (int x,int y, ll v) { for(;y<N;y+=y&-y)TR[x][y]+=v;} ll Ask (int  x,int y) {ll ans=0; for(;y;y-=y&-y) ans+=TR[x][y];returnAns;} void Solve (intP,llx,intIintf) {ll now=0; while(x%prime[i]==0)x/=prime[i],now++; Change (i,p,f*now);}intMain () { for(intI=2; i<=281; i++)if(!b[i]) {prime[++top]=i;inv[top]=cal (prime[top],mod-2); for(intj=2*i; j<=281; j+=i) b[j]=1; } for(intI=1; i<n;i++) Change (2I1), a[i]=3; Q=SC (); while(q--) {if(SC ()) {int x=SC (),y=SC (); for(intI=1; i<= -; i++) {if(a[x]%prime[i]==0) Solve (x, a[x],i,-1);if(y%prime[i]==0) Solve (x,yI1); } a[x]=y; }Else{intL=SC (), R=SC (); ll ans=1; for(intI=1; i<= -; i++) {ll res=ask (i,r)-ask (i,l-1);if(res) Ans=ans*cal(prime[i],res-1)*(prime[i]-1)%mod; }printf("%d\ n", ans); }    }return 0;}

3813: Odd Country | tree Array | Euler function

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.