Bzoj 3813 Odd Country Euler function + segment tree + multiplicative inverse

Source: Internet
Author: User
Tags bitset

The main idea: to give a sequence, support the modification operation, the sequence of the series of the product of the Euler function. The maximum quality factor for each number does not exceed 281.


Idea:φ (n) = n * (1-1/p1) * (1-1/p2) * (1-1/p3) * (1-1/P4) ... * (1-1/PN)

= N/(P1 * p2 * p3 * ... * pn) * ((p1-1) * (p2-1) * (p3-1) * ... * (pn-1))

So this thing just need to maintain the index in the interval, with bitset maintenance of factorization, set out to use the multiplication inverse, no.


CODE:

#include <bitset> #include <cstdio> #include <cstring> #include <iostream> #include < algorithm> #define P 19961993#define MAX 100010using namespace std; #define LEFT (POS << 1) #define RIGHT (POS <& Lt 1|1) #define MAX (a) > (b)?          (a):(B)) struct ask{int flag,x,y;    void Read () {scanf ("%d%d%d", &flag,&x,&y);  }}ask[max];    struct segtree{bitset<61> Prime;          int total; Segtree (bitset<61> _,int __):p Rime (_), total (__) {} segtree () {} Segtree operator + (const segtree &a) const    {return Segtree (Prime|a.prime, (long Long) total * a.total% P);  }}tree[max << 2];  int G[300],g[300];long long Inv[300];int asks,cnt;    inline bool Judge (int x) {for (int i = 2; I * i <= x; ++i) if (x% i = = 0) return false;  return true;}    void Shake () {inv[1] = 1;  for (int i = 2; I <= 281; ++i) inv[i] = (P/i) * inv[p% i]% P;}  void Pretreatment () {  Shake ();    int cnt = 0;  for (int i = 2; I <= 281; ++i) if (Judge (i)) g[i] = ++cnt,g[cnt] = i;}        void Buildtree (int l,int r,int POS) {if (L = = r) {Tree[pos].prime[g[3]] = 1;        Tree[pos].total = 3;    return;    } int mid = (L + r) >> 1;    Buildtree (L,mid,left);    Buildtree (mid + 1,r,right); Tree[pos] = Tree[left] + tree[right];    } segtree Ask (int l,int r,int x,int y,int pos) {if (L = = x && r = = y) return tree[pos];    int mid = (L + r) >> 1;    if (y <= mid) return Ask (L,mid,x,y,left);    if (x > Mid) return Ask (mid + 1,r,x,y,right);    Segtree left = Ask (L,mid,x,mid,left);    Segtree right = Ask (mid + 1,r,mid + 1,y,right);  return left + right;}        void Modify (int l,int r,int x,int pos,segtree c) {if (L = = r) {Tree[pos] = C;    return;    } int mid = (L + r) >> 1;    if (x <= mid) Modify (L,MID,X,LEFT,C);    else Modify (mid + 1,r,x,right,c); Tree[pos] = Tree[left] + treE[right];}    int main () {pretreatment ();    Cin >> asks; for (int i = 1; I <= asks; ++i) Ask[i].    Read ();    CNT = MAX-1;    Buildtree (1,cnt,1);        for (int flag,x,y,i = 1; I <= asks; ++i) {flag = Ask[i].flag;        x = Ask[i].x,y = Ask[i].y;            if (flag) {bitset<61> p;            for (int j = 1; J <=; ++j) if (y% g[j] = = 0) P[j] = 1;            Segtree c (p,y);        Modify (1,CNT,X,1,C);            } else {Segtree ans = Ask (1,cnt,x,y,1); for (int j = 1; J <=; ++j) if (Ans.prime[j]) {ans.total = (long long) ans.total * I                    NV[G[J]])% P;                Ans.total = ((Long Long) ans.total * (G[j]-1))% P;        } printf ("%d\n", ans.total); }} return 0;}


Bzoj 3813 Odd Country Euler function + segment tree + multiplicative inverse

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.