codeforce385c tree-like array + element factorization

Source: Internet
Author: User

Main topic:

Ask for more than one interval, each occurrence of the number of primes in the query interval to calculate how many numbers can be divisible by this prime.

Then sum the corresponding values of all primes

This is because the initial given number does not exceed 10000000, up to 670000 primes

It is meaningless to reach 1e9 at the end of a given interval, as long as more than 10000000 of the following are represented by the last number.

The number of primes is then used as the point of the tree array, preserving the corresponding point prefixes and

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <ctime>6#include <cstdlib>7#include <vector>8#include <algorithm>9 using namespacestd;Ten #definell Long Long One #defineN 10001000 A #defineM 670000 - #definePII pair<int,int> - #defineLowbit (x) x& (-X) the intprime[m+5], tot; - BOOLcheck[n+5]; -  - voidGet_prim () + { -      for(intI=2; I<=n; i++){ +         if(!check[i]) prime[tot++] =i; A          for(intj=0; J<tot; J + +){ at             if(LL) i*prime[j]>n) Break; -CHECK[I*PRIME[J]] =true; -             if(i%prime[j]==0) Break; -         } -     } - } in  - intHASH1 (intx) to { +     if(x>10000000)return 664580;//664579 is the number of 10000000 inside primes -     intL=0, r=tot-1, ans=0; the      while(l<=0) { *         intm = (l+r) >>1; $         if(prime[m]>=x) {ans = m, r=m-1;}Panax Notoginseng         Elsel=m+1; -     } the     returnans+1; + } A  the intHASH2 (intx) + { -     if(x>10000000)return 664580; $     intL=0, r=tot-1, ans=0; $      while(l<=R) { -         intm = (l+r) >>1; -         if(prime[m]<=x) {ans = m, l=m+1;} the         Elser=m-1; -     }Wuyi     returnans+1; the } -  Wu ll Sum[m]; -  About voidAddintXintV) { for(intI=x; I<=tot; I+=lowbit (i)) sum[i] + =v;} $  -ll query (intx) - { -LL ret =0; A      for(intI=x; I>0; I-=lowbit (i)) ret+=Sum[i]; +     returnret; the } -  $ voidFenjie (intx) the { the     intMX = (int) sqrt (x+0.5); the      for(intI=0; I<tot; i++){ the         if(prime[i]*prime[i]>x) Break; -         if(x%prime[i]==0){ in           //cout<< "in:" <<i<< "" <<prime[i]<<endl; theAdd (i+1,1); the              while(x%prime[i]==0) x/=Prime[i]; About         } the     } the     if(x>1){ the         intpos = Lower_bound (Prime, Prime+tot, X)-Prime; +Add (pos+1,1); -     } the }Bayi  the intMain () { the    //freopen ("a.in", "R", stdin); -    //freopen ("OUT.txt", "w", stdout); - Get_prim (); the     intN, m, S, T; the      while(~SCANF ("%d", &N)) the     { the          for(intI=0; I<n; i++){ -             intx; thescanf"%d", &x); the Fenjie (x); the         }94scanf"%d", &m); the          while(m--){ thescanf"%d%d", &s, &t); the             intP1 = Hash1 (s), p2 =Hash2 (t);98           //cout<<p1<< "" <<p2<<endl; Aboutprintf"%i64d\n", query (p2)-query (p1-1)); -         }101     }102}

codeforce385c tree-like array + element factorization

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.