「2018 南京网络预赛」Sum - 线性筛 | Menci's Blog



「2018 南京网络预赛」Sum - 线性筛 | Menci's Blog

定义 f(x)f(x) 为满足以下条件的有序二元组 (a,b)(a,b) 的方案数(即 (a,b)(a,b)(b,a)(b,a) 被认为是不同的方案):

  1. x=abx=ab
  2. aabb 均为无平方因子数(即其因子中没有除 11 以外的完全平方数)。

i=1nf(i)\sum\limits_{i=1}^nf(i)n2×107n\leq 2\times 10^7

链接

计蒜客 30999

题解

显然,f(n)=dnμ(d)μ(nd)f(n)=\sum\limits_{d|n}|\mu(d)\mu(\frac{n}{d})| 是积性函数,考虑线性筛。

  1. xx 为素数时,f(x)=2f(x)=2,即 (1,x)(1,x)(x,1)(x,1)
  2. xx 的最小质因子为 pp,且 p\not\mid\frac{x}{p} 时,f(x)=2f(px)f(x)=2f(\frac{p}{x})
  3. xx 的最小质因子为 pp,且 pxpp\mid\frac{x}{p} 时:
    • 如果 pxp2p|\frac{x}{p^2},那么 xxpp 的指数至少为 33,即无论如何划分 (a,b)(a,b),两个数中一定有一个数中 pp 的指数为 22,即不存在合法的划分方案。
    • 否则,xxpp 的指数至少为 22,把这两个 pp 分别分给 (a,b)(a,b) 中的 aabb,剩余的 xp\frac{x}{p} 就是一个子问题了,即 f(x)=f(xp2)f(x)=f(\frac{x}{p^2})


Read full article from 「2018 南京网络预赛」Sum - 线性筛 | Menci's Blog


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts