CF#235E. Number Challenge

传送门

可以理解为上一道题的扩展板..

然后我们就可以YY出这样一个式子

${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^c[gcd(i,j)=gcd(i,k)=gcd(j,k)=1]\lfloor\frac{a}{i}\rfloor\lfloor\frac{b}{j}\rfloor\lfloor\frac{c}{k}\rfloor}$

然后我们枚举第一维,排除掉不和第一维互质的数大力反演就OK啦。

这里介绍另一种很神奇(麻烦)方法,当然这个和反演的关系就没那么大了:

首先设$f(k)=\sum\limits_{i=1}^{a}\sum\limits_{j=1}^{b}[k=i \times j]$

然后得到$ans=\sum\limits_{i=1}^{a\times b} f(i)\sum\limits_{j=1}{d(i \times j)}$

$ans=\sum\limits_{i=1}^{a\times b} f(i)\sum\limits_{j=1}^{c}{d(i \times j)}$
$ans=\sum\limits_{i=1}^{a\times b} f(i)\sum\limits_{j=1}^{c}\sum\limits_{u=1}^{i}\sum\limits_{v=1}^{j}[gcd(u,v)=1]\lfloor\frac{i}{u}\rfloor\lfloor\frac{j}{v}\rfloor$
$ans=\sum\limits_{i=1}^{a\times b}\sum\limits_{j=1}^{c}[gcd(i,j)=1]\sum\limits_{u=1}^{\frac{a\times b}{i}}f(u\times i)\lfloor \frac{c}{j}\rfloor$

不妨设$S(i)=\sum\limits_{u=1}^{\frac{a\times b}{i}}f(u\times i)$

得到:

$ans=\sum\limits_{i=1}^{a\times b}\sum\limits_{j=1}^{c}[gcd(i,j)=1]S(i)\lfloor \frac{c}{j}\rfloor$

$ans=\sum\limits_{i=1}^{a\times b}\sum\limits_{j=1}^{c}\sum\limits_{d|gcd(i,j)}\mu(d)S(i)\lfloor \frac{c}{j}\rfloor$

不妨设$Q(k)=\sum\limits_{i=1}^{k}\lfloor \frac{k}{i} \rfloor$

得到:

$ans=\sum\limits_{i=1}^{c}\mu(i)\sum\limits_{j=1}^{\frac{a\times b}{i}}S(i\times j)\sum\limits_{k=1}^{\frac{c}{i}}Q(k)$

不妨设$P(k)=\sum\limits_{i=1}^{\frac{a\times b}{k}}S(i\times k)$

最后得到$ans=\sum\limits_{i=1}^{c}\mu(i)P(i)Q(i)$

大力预处理即可。

//CF235E
//by Cydiater
//2017.2.22
#include <iostream>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <vector>
#include <complex>
using namespace std;
#define ll int
#define up(i,j,n)	for(ll i=j;i<=n;i++)
#define down(i,j,n)	for(ll i=j;i>=n;i--)
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b)	a=min(a,b)
const ll MAXN=4e6+5;
const ll mod=1073741824;
inline ll read(){
	char ch=getchar();ll x=0,f=1;
	while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)f=-1;ch=getchar();}
	while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
	return x*f;
}
ll A,B,C,AB,prime[MAXN],P[MAXN],S[MAXN],f[MAXN],Q[MAXN],miu[MAXN],cnt;
bool vis[MAXN];
namespace solution{
	void Prepare(){
		A=read();B=read();C=read();AB=A*B;
		miu[1]=1;
		up(i,2,C){
			if(!vis[i]){prime[++cnt]=i;miu[i]=-1;}
			up(j,1,cnt){
				if(i*prime[j]>C)break;
				vis[i*prime[j]]=1;
				if(i%prime[j])miu[i*prime[j]]=-miu[i];
				else break;
			}
		}
		up(i,1,A)up(j,1,B)f[i*j]++;
		up(i,1,AB)for(ll j=i;j<=AB;j+=i)
			(S[i]+=f[j])%=mod;
		up(i,1,AB)for(ll j=i;j<=AB;j+=i)
			(P[i]+=S[j])%=mod;
		ll pos;
		up(i,1,C){
			for(ll j=1;j<=i;j=pos+1){
				pos=i/(i/j);
				Q[i]+=(pos-j+1)*(i/j);
				(Q[i]+=mod)%=mod;
			}
		}
	}
	void Solve(){
		ll ans=0;
		up(i,1,C){
			(ans+=miu[i]*P[i]*Q[C/i])%=mod;
			(ans+=mod)%=mod;
		}
		cout<<ans<<endl;
	}
}
int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	Prepare();
	Solve();
	//cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
	return 0;
}
时间: 2024-10-13 16:04:53

CF#235E. Number Challenge的相关文章

Codeforces 235E Number Challenge

题目大意 求  ,d是约数个数函数.答案对1073741824 (2^30)取模. 题解 首先我们令f(i)为前两维乘积是i的个数. 那么我们有 你需要知道这么一个式子 这个公式很经典就不加赘述了.之后是愉快的推倒.为了方便令 转换枚举对象枚举x,y 接下来就是喜闻乐见的反演 转换枚举对象的套路 这样就可以ablogab来求了.我极限数据没跑过去直接打的表--惨--人傻自带大常数-- 1 #include<iostream> 2 #include<cstdio> 3 #includ

Easy Number Challenge(暴力,求因子个数)

Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 236B Appoint description:  System Crawler  (2016-04-26) Description Let's denote d(n) as the number of divisors of a

CF 27E Number With The Given Amount Of Divisors

A - Number With The Given Amount Of Divisors Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed

【codeforces 235E】 Number Challenge

http://codeforces.com/problemset/problem/235/E (题目链接) 题意 给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)}$ Solution 莫比乌斯反演,推啊推式子. 有这样一个公式,就是约数个数和那道题的推广吧.$${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^c[gcd(

CF 466C Number of Ways(数学 / 思维 / DP)

题目链接:http://codeforces.com/problemset/problem/466/C 题目: You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each

Codeforces 235 E Number Challenge

Discription Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: Find the sum modulo 1073741824 (230). Input The first line contains three space-sep

Lintcode: Update Bits

Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e g , M becomes a substring of N located at i and starting at j) Have you met this question in a real interview? Yes Ex

[lintcode medium]Maximum Subarray II

Maximum Subarray II Given an array of integers, find two non-overlapping subarrays which have the largest sum. The number in each subarray should be contiguous. Return the largest sum. Example For given [1, 3, -1, 2, -1, 2], the two subarrays are [1,

Spearman&#39;s rank correlation coefficient 和 Pearson correlation coefficient详细

In statistics, Spearman's rank correlation coefficient or Spearman's rho, named after Charles Spearman and often denoted by the Greek letter (rho) or as , is a nonparametric measure of statistical dependence between two variables. It assesses how wel