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 ab and c. Your task is to calculate the following sum:

Find the sum modulo 1073741824 (230).

Input

The first line contains three space-separated integers ab and c (1?≤?a,?b,?c?≤?2000).

Output

Print a single integer — the required sum modulo 1073741824 (230).

Example

Input

2 2 2

Output

20

Input

4 4 4

Output

328

Input

10 10 10

Output

11536

Note

For the first example.

  • d(1·1·1)?=?d(1)?=?1;
  • d(1·1·2)?=?d(2)?=?2;
  • d(1·2·1)?=?d(2)?=?2;
  • d(1·2·2)?=?d(4)?=?3;
  • d(2·1·1)?=?d(2)?=?2;
  • d(2·1·2)?=?d(4)?=?3;
  • d(2·2·1)?=?d(4)?=?3;
  • d(2·2·2)?=?d(8)?=?4.

So the result is 1?+?2?+?2?+?3?+?2?+?3?+?3?+?4?=?20.

我是直接暴力合并a和b,然后设 to(i) 为有多少对有序对(x,y) 满足 1<=x<=a 且 1<=y<=b 且 x*y==i。

然后式子就是 Σ(i=1 to a*b) to(i) Σ(j=1 to c) d(i*j)

这个用约数个数函数的基本式子就可以化简,最后可以 用不到 O(a*b*log(a*b)) 的时间计算出答案。

所以a,b就取三个数中最小的两个就行了。

#include<bits/stdc++.h>
#define ll long long
#define maxn 4000000
using namespace std;
const int ha=1<<30;
int a,b,c,miu[maxn+5];
int zs[maxn/5],t=0,D,low[maxn+5];
int d[maxn+5],to[maxn+5],ans=0;
bool v[maxn+5];

inline void init(){
	for(int i=1;i<=a;i++)
	    for(int j=1;j<=b;j++) to[i*j]++;
	miu[1]=d[1]=low[1]=1;

	for(int i=2;i<=maxn;i++){
		if(!v[i]) zs[++t]=i,miu[i]=-1,low[i]=i,d[i]=2;
		for(int j=1,u;j<=t&&(u=zs[j]*i)<=maxn;j++){
			v[u]=1;

			if(!(i%zs[j])){
				low[u]=low[i]*zs[j];
				if(low[i]==i) d[u]=d[i]+1;
				else d[u]=d[low[u]]*d[i/low[i]];
				break;
			}
			low[u]=zs[j],d[u]=d[i]<<1,miu[u]=-miu[i];
		}
	}

	for(int i=1;i<=maxn;i++) d[i]+=d[i-1];
}

inline int add(int x,int y){
	x+=y;
	return x>=ha?x-ha:x;
}

inline void calc(){
	for(int i=1,sum;i<=c;i++) if(miu[i]){
		sum=0;
		for(int j=i;j<=D;j+=i) sum=add(sum,to[j]*(ll)(d[j/i]-d[j/i-1])%ha);
		sum=sum*(ll)d[c/i]%ha;
		if(miu[i]==1) ans=add(ans,sum);
		else ans=add(ans,ha-sum);
	}
	printf("%d\n",ans);
}

int main(){
	scanf("%d%d%d",&a,&b,&c);
	if(a>b) swap(a,b);
	if(a>c) swap(a,c);
	if(b>c) swap(b,c);
	D=a*b;

	init();
	calc();

	return 0;
}

  

原文地址:https://www.cnblogs.com/JYYHH/p/8531071.html

时间: 2024-10-08 05:10:43

Codeforces 235 E Number Challenge的相关文章

【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(

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

Codeforces 55D Beautiful Number

Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. Input The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two

[2016-04-15][codeforces][660][D][Number of Parallelograms]

时间:2016-04-15 18:40:17 星期五 题目编号:[2016-04-15][codeforces][660][D][Number of Parallelograms] 题目大意:给定n个点的坐标,问这些点能组成多少个平行四边形 分析: 每个平行四边形对角线互相平分,所以只要两条边的交点一样,那么这两条边(斜边)所对应的四边形就一定是平行四边形 所以,枚举所有交点,计算相同交点的个数 CntiCnti,那么ans=∑Cnti×(Cnti?1)2ans=∑Cnti×(Cnti?1)2

Codeforces 235E Number Challenge

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

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

codeforces 251C C. Number Transformation(数论+dp)

题目链接: codeforces 251C 题目大意: 给出两个数a,b,k有两种操作,a-=1,或者a-=a%x(2<=x<=k),问最少需要多少步操作能够使a变成b 题目分析: 首先我们考虑数据范围小的怎么做,定义状态dp[i]表示从a到达i最少需要多少步 {dp[i?1]=min(dp[i?1],dp[i]+1)dp[i?i%x]=min{(dp[i?i%x],dp[i]+1)|2≤x≤k} 那么我们考虑题目给出的数据范围好大,直接做肯定超时,那么考虑每步操作只有a-=1和a-=a%x,

CodeForces - 724G Xor-matic Number of the Graph

Discription You are given an undirected graph, constisting of n vertices and m edges. Each edge of the graph has some non-negative integer written on it. Let's call a triple (u,?v,?s) interesting, if 1?≤?u?<?v?≤?n and there is a path (possibly non-si

codeforces 622. Optimal Number Permutation 构造

题目链接 假设始终可以找到一种状态使得值为0, 那么两个1之间需要隔n-2个数, 两个2之间需要隔n-3个数, 两个3之间隔n-4个数. 我们发现两个三可以放到两个1之间, 同理两个5放到两个3之间....这样就构造好了. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmat