题意

题目链接

Sol

不想打公式了,最后就是求一个

\(\sum_{i=1}^n ig(\frac{N}{i})\)

\(g(i) = \sum_{i=1}^n \phi(i) i^2\)

拉个\(id2\)卷一下

这个博客推的狠详细

  1. #include<bits/stdc++.h>
  2. #define int long long
  3. #define LL long long
  4. using namespace std;
  5. const int MAXN = 1e6 + 10, mod = 1e9 + 7, INF = 1e9 + 10, INV2 = 500000004, INV6 = 166666668, B = 1e6;
  6. template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
  7. template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
  8. template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
  9. template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
  10. void print(int x) {
  11. if(!x) return ;
  12. print(x / 10);
  13. putchar(x % 10 + '0');
  14. }
  15. inline int read() {
  16. char c = getchar(); int x = 0, f = 1;
  17. while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
  18. while(c >= '0' && c <= '9') x = 1ll * x * 10 + c - '0', c = getchar();
  19. return x * f;
  20. }
  21. int g[MAXN], phi[MAXN], mu[MAXN], vis[MAXN], prime[MAXN], tot;
  22. map<int, int> mp;
  23. int sum(int N) {return mul(mul(N % mod, add(N, 1)), INV2);}
  24. int sum2(int N) {return mul(mul(N % mod, mul(add(N, 1), mul(2, N) + 1)), INV6);}
  25. int sum3(int N) {return mul(sum(N), sum(N));}
  26. void sieve(int N) {
  27. vis[1] = phi[1] = mu[1] = 1;
  28. for(int i = 2; i <= N; i++) {
  29. if(!vis[i]) prime[++tot] = i, mu[i] = -1, phi[i] = i - 1;
  30. for(int j = 1; j <= tot && i * prime[j] <= N; j++) {
  31. vis[i * prime[j]] = 1;
  32. if(i % prime[j]) phi[i * prime[j]] = phi[i] * phi[prime[j]], mu[i * prime[j]] = -mu[i];
  33. else {mu[i * prime[j]] = 0; phi[i * prime[j]] = phi[i] * prime[j]; break;};
  34. }
  35. }
  36. for(int i = 1; i <= N; i++) g[i] = add(g[i - 1], mul(phi[i], mul(i, i)));
  37. }
  38. LL dsieve(int N) {
  39. if(N <= B) return g[N];
  40. else if(mp[N]) return mp[N];
  41. LL t = sum3(N);
  42. for(int i = 2, nxt; i <= N; i = nxt + 1) {
  43. nxt = N / (N / i);
  44. add2(t, -mul(add(sum2(nxt), -sum2(i - 1)), dsieve(N / i)));
  45. }
  46. return mp[N] = t;
  47. }
  48. signed main() {
  49. sieve(B);
  50. int N = read(), ans = 0;
  51. for(int i = 1, nxt; i <= N; i = nxt + 1) {
  52. nxt = N / (N / i);
  53. add2(ans, mul(add(sum(nxt), -sum(i - 1)), dsieve(N / i)));
  54. }
  55. print(ans);
  56. return 0;
  57. }

51nod1238 最小公倍数之和 V3(莫比乌斯反演)的更多相关文章

  1. 51nod1238 最小公倍数之和 V3 莫比乌斯函数 杜教筛

    题意:求\(\sum_{i = 1}^{n}\sum_{j = 1}^{n}lcm(i, j)\). 题解:虽然网上很多题解说用mu卡不过去,,,不过试了一下貌似时间还挺充足的,..也许有时间用phi ...

  2. [51nod1238]最小公倍数之和V3

    来自FallDream的博客,未经允许,请勿转载,谢谢. ----------------------------------------------------------------------- ...

  3. 51nod1238 最小公倍数之和 V3

    又被这神仙题给坑爆了. 神仙题解. 一开始我把lcm变成ij/gcd然后按照常规套路去推,推到最后发现不是miu * Id而是miu · Id......这还搞鬼啊. 正解居然跟这个差不多,先转成求其 ...

  4. 51Nod.1237.最大公约数之和 V3(莫比乌斯反演 杜教筛 欧拉函数)

    题目链接 \(Description\) \(n\leq 10^{10}\),求 \[\sum_{i=1}^n\sum_{j=1}^ngcd(i,j)\ mod\ (1e9+7)\] \(Soluti ...

  5. [51Nod1238]最小公倍数之和 V3[杜教筛]

    题意 给定 \(n\) ,求 \(\sum_{i=1}^n \sum_{j=1}^n lcm(i,j)\). \(n\leq 10^{10}\) 分析 推式子 \[\begin{aligned} an ...

  6. 51nod1238. 最小公倍数之和 V3(数论)

    题目链接 https://www.51nod.com/Challenge/Problem.html#!#problemId=1238 题解 本来想做个杜教筛板子题结果用另一种方法过了...... 所谓 ...

  7. [51nod1238] 最小公倍数之和 V3(杜教筛)

    题面 传送门 题解 懒了--这里写得挺好的-- //minamoto #include<bits/stdc++.h> #define R register #define ll long ...

  8. 51nod 1238 最小公倍数之和 V3

    51nod 1238 最小公倍数之和 V3 求 \[ \sum_{i=1}^N\sum_{j=1}^N lcm(i,j) \] \(N\leq 10^{10}\) 先按照套路推一波反演的式子: \[ ...

  9. 51NOD 1238 最小公倍数之和 V3 [杜教筛]

    1238 最小公倍数之和 V3 三种做法!!! 见学习笔记,这里只贴代码 #include <iostream> #include <cstdio> #include < ...

随机推荐

  1. Spark基础-scala学习(四、函数式编程)

    函数式编程 将函数赋值给变量 匿名函数 高阶函数 高级函数的类型推断 scala的常用高阶函数 闭包 sam转换 currying函数 return 将函数赋值给变量 scala中的函数是一等公民,可 ...

  2. [转载]PHP中PSR-[0-4]规范

      PHP是世界上最伟大的语言,这一点是毋庸置疑的吧.哈哈哈哈哈哈 .这个霸气的开头不错!(^__^) 但是正是因为伟大,所以用的人也就多了,人一多,再牛逼再伟大的东西,都会产生问题,逐渐就造成了很多 ...

  3. Java-二进制转10进制原理机制

    任何文件在计算机储存时都是以二进制储存的,由 1和0 组成,如: 101010101010100111110100101010 现在有一组二进制数据: 10010110 那么他转成10进制是多少呢(我 ...

  4. 提纲挈领webrtc音频处理算法之写在前面的话

    最近工作用到了webrtc,发现webrtc是个宝库,里面有很多东西值得好好研究. 搜了这方面不少资料,发现介绍使用webrtc的不少,但是针对里面一些算法研究的 不多.特别是能把算法说的简洁明了的更 ...

  5. Axure安装、破解、汉化全套

    最近公司准备使用敏捷开发流程,然后刚好需要Axure这个软件,就去找了些资源分享给大家,希望对大家有所帮助: 全套安装,破解,汉化下载地址: 链接: https://pan.baidu.com/s/1 ...

  6. 基于 Consul 实现 MagicOnion(GRpc) 服务注册与发现

    0.简介 0.1 什么是 Consul Consul是HashiCorp公司推出的开源工具,用于实现分布式系统的服务发现与配置. 这里所谓的服务,不仅仅包括常用的 Api 这些服务,也包括软件开发过程 ...

  7. Linux编程 21 shell编程(环境变量,用户变量,命令替换)

    一.概述 这篇介绍shell的变量使用,跟其实语言一样,都有声明变量,使用变量,在shell中变量允许你临时地将信息存储中shell脚本中,以便和脚本的其他命令一起使用. 1.1 环境变量 在前面章节 ...

  8. C++常见笔试题

    1.实现字符串转整数的函数:int atoi(const char *nptr) 2.实现数组折半查找:int BinarySearch(int a[],int len, int key) 3.实现字 ...

  9. 通过keras例子理解LSTM 循环神经网络(RNN)

    博文的翻译和实践: Understanding Stateful LSTM Recurrent Neural Networks in Python with Keras 正文 一个强大而流行的循环神经 ...

  10. uniq命令

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html uniq是去重,不相邻的行不算重复值. uniq [OPTIO ...