题意:求,其中d(x) 表示 x 的约数个数。

析:其实是一个公式题,要知道一个结论

知道这个结论就好办了。

然后就可以解决这个问题了,优化就是记忆化gcd。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 2000 + 1;
const int maxm = 2e4 + 10;
const int mod = 1073741824;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} bool vis[maxn];
int g[maxn][maxn], mu[maxn], prime[maxn]; void Moblus(){
mu[1] = 1; int tot = 0;
for(int i = 2; i <= n; ++i){
if(!vis[i]) prime[tot++] = i, mu[i] = -1;
for(int j = 0; j < tot; ++j){
int t = i * prime[j];
if(t > n) break;
vis[t] = 1;
if(i % prime[j] == 0) break;
mu[t] = -mu[i];
}
}
} int ggcd(int a, int b){
if(!b) return a;
if(g[a][b]) return g[a][b];
return g[a][b] = g[b][a] = gcd(b, a%b);
} int solve(int n, int d, int k){
int ans = 0;
for(int i = 1; i <= n; ++i)
if(ggcd(d*i, k) == 1) ans += n / i;
return ans;
} int main(){
int t;
scanf("%d %d %d", &n, &m, &t);
if(n > m) swap(n, m);
if(n > t) swap(n, t);
if(t > m) swap(m, t);
Moblus();
int ans = 0;
for(int i = 1; i <= t; ++i){
int tmp = 0;
for(int j = 1; j <= n; ++j) if(mu[j])
tmp += mu[j] * solve(n/j, j, i) * solve(m/j, j, i);
ans += t/i * tmp;
}
printf("%d\n", (ans%mod+mod)%mod);
return 0;
}

  

  

CodeForces 235E Number Challenge (莫比乌斯反演)的更多相关文章

  1. Codeforces 235E. Number Challenge DP

    dp(a,b,c,p) = sigma ( dp(a/p^i,b/p^j,c/p^k) * ( 1+i+j+k) ) 表示用小于等于p的素数去分解的结果有多少个 E. Number Challenge ...

  2. Codeforces 235E Number Challenge

    http://codeforces.com/contest/235/problem/E 远距离orz......rng_58 证明可以见这里(可能要FQ才能看到) 还是copy一下证明吧: 记 $$f ...

  3. Codeforces 809E Surprise me! [莫比乌斯反演]

    洛谷 Codeforces 非常套路的一道题,很适合我在陷入低谷时提升信心-- 思路 显然我们需要大力推式子. 设\(p_{a_i}=i\),则有 \[ \begin{align*} n(n-1)an ...

  4. Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)

    Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...

  5. CF#235E. Number Challenge

    传送门 可以理解为上一道题的扩展板.. 然后我们就可以YY出这样一个式子 ${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{ ...

  6. Codeforces.809E.Surprise me!(莫比乌斯反演 虚树)

    题目链接 \(Description\) 给定一棵树,求\[\frac{1}{n(n-1)/2}\times\sum_{i\in[1,n],j\in[1,n],i\neq j}\varphi(a_i\ ...

  7. 【codeforces 235E】 Number Challenge

    http://codeforces.com/problemset/problem/235/E (题目链接) 题意 给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum ...

  8. 【CodeForces】915 G. Coprime Arrays 莫比乌斯反演,前缀和,差分

    Coprime Arrays CodeForces - 915G Let's call an array a of size n coprime iff gcd(a1, a2, ..., *a**n) ...

  9. codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)

    题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...

随机推荐

  1. ubuntu下tomcat的安装及注册成系统服务

    在ubuntu下tomcat的安装有两种方式,第一种是下载二进制文件,解压安装:第二种则是使用apt-get自动下载.这里不推荐第二种方法安装,因为这种方法安装会像天女散花一样把安装的文件散落在系统的 ...

  2. 489. Robot Room Cleaner扫地机器人

    [抄题]: Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or block ...

  3. swift - iOS10之后的加速器

    import UIKit //1.加速器框架 import CoreMotion class ViewController: UIViewController { //1.创建运动管理者 必须设置为 ...

  4. MyBatis高级映射查询(3)

    一.数据库数据和项目搭建过程 1.主要要四张表,分别为user用户信息表.items商品表.orderdetail订单明细表.orders订单表.表的结构和数据如下: 表结构 CREATE DATAB ...

  5. Android View 深度分析requestLayout、invalidate与postInvalidate

    前言 前几篇文章中,笔者对View的三大工作流程进行了详细分析,而这篇文章则详细讲述与三大工作流程密切相关的两个方法,分别是requestLayout和invalidate,如果对Viwe的三个工作流 ...

  6. rosrun和roslaunch

    rosrun allows you to run an executable(可执行) in an arbitrary(任意) package without having to cd (or ros ...

  7. Android Studio 使用入门

    Android Studio 快捷键 Action Mac OSX Win/Linux 注释代码(//) Cmd + / Ctrl + / 注释代码(/**/) Cmd + Option + / Ct ...

  8. c++ opencv 3.2 +Mfc VS2015窗体显示图片方法

    本文仅涉及一些核心步骤,具体 OpenCV 的配置以及其他的细节问题,请参考 VS2010 / MFC + OpenCV 2.4.1打开图片. 1. 新建 MFC 对话框项目 基于对话框,不使用Uni ...

  9. svg 配合cesium使用

    ---恢复内容开始--- 1.svg简介 在 2003 年一月,SVG 1.1 被确立为 W3C 标准. 参与定义 SVG 的组织有:太阳微系统.Adobe.苹果公司.IBM 以及柯达. 与其他图像格 ...

  10. 全局组建封装(挂载到vue实例的原型中,通过this访问)

    主题:组建的封装  一:install注册的全局封装(v-grid九宫格组建)               1.九宫格的封装主要有三个api 点击功能 每行个数 是否隐藏边框              ...