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-separated integers a, b and c (1 ≤ a, b, c ≤ 2000).
Output
Print a single integer — the required sum modulo 1073741824 (230).
Example
2 2 2
20
4 4 4
328
10 10 10
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;
}
Codeforces 235 E Number Challenge的更多相关文章
- [codeforces 235]A. LCM Challenge
[codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...
- 【codeforces 235E】 Number Challenge
http://codeforces.com/problemset/problem/235/E (题目链接) 题意 给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum ...
- 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 ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Codeforces 55D Beautiful Number
Codeforces 55D Beautiful Number a positive integer number is beautiful if and only if it is divisibl ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge
B. Easy Number Challenge time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Java实现 蓝桥杯 算法训练 Number Challenge(暴力)
试题 算法训练 Number Challenge 资源限制 时间限制:3.0s 内存限制:512.0MB 问题描述 定义d(n)为n的约数个数.现在,你有三个数a,b,c.你的任务是计算下面式子mod ...
- Codeforces 235E Number Challenge
http://codeforces.com/contest/235/problem/E 远距离orz......rng_58 证明可以见这里(可能要FQ才能看到) 还是copy一下证明吧: 记 $$f ...
- 洛谷 P3327 [SDOI2015]约数个数和 || Number Challenge Codeforces - 235E
https://www.luogu.org/problemnew/show/P3327 不会做. 去搜题解...为什么题解都用了一个奇怪的公式?太奇怪了啊... 公式是这样的: $d(xy)=\sum ...
随机推荐
- 深入理解FIFO(包含有FIFO深度的解释)——转载
深入理解FIFO(包含有FIFO深度的解释) FIFO: 一.先入先出队列(First Input First Output,FIFO)这是一种传统的按序执行方法,先进入的指令先完成并引退,跟着才执行 ...
- phpmyadmin提示The mbstring extension is missing的解决方法
解决办法:安装php-mbstring yum install php-mbstring
- golang(go语言)调试和查看gc信息,以及gc信息解析
这里记录一下调试golang gc的方法 启用gc打印: # GODEBUG=gctrace=1 go run ./main.go 程序启动后gc将打印如下信息: gc 65 @16.996s 0%: ...
- SSAS——MDX基础
一.基本概念 MDX:一种查询语言,从多维的数据集单元格中检索数据.支持两种不同的模式: 1.表达式语言:定义和操纵Analysis Services对象和数据以计算值 2.查询语言:从Analysi ...
- src与href的区别
href: 是指向网络资源所在位置,建立和当前元素(锚点)或当前文档(链接)之间的链接,用于超链接. src:是指向外部资源的位置,指向的内容将会嵌入到文档中当前标签所在位置:在请求src资源时会将其 ...
- CSS 工程化 小结
CSS 工程化 组成:1.组织 (代码目录)2.优化(那种实现方式更好) 3.构建(代码完成后需要经过哪些处理步骤) 4.维护 常见问题 1.如何解决 CSS 模块化问题 1.Less Sass 等C ...
- 网页静态化解决方案Freemarker
序言: 沉淀了三个月,逐步将自己最近两年在公司中用到的技术和知识点,重新整理归纳了下,对比以前可以发现,现在技术更新越来越快,也越来越成熟,在互联网企业,用到的技术也更先进,更领先,比如微服务.分布式 ...
- Netcore 基础之TagHelper知识
饮水思源,来自:http://www.cnblogs.com/liontone 的BLOG中关于taghelper中的内容 概要 TagHelper是ASP.NET 5的一个新特性.也许在你还没有听说 ...
- js---post与get请求的区别
request获取请求参数 最为常见的客户端传递参数方式有两种: 浏览器地址栏直接输入:一定是GET请求: 超链接:一定是GET请求: 表单:可以是GET,也可以是POST,这取决与<form& ...
- 和为s的两个数字 【微软面试100题 第十四题】
题目要求: 输入一个递增排序的数组和一个数字s,在数组中查找两个数,使得它们的和正好是s.如果有多对数字的和等于s,输出任意一对即可. 例如输入数组{1,2,4,7,11,15}和数字15.由于4+1 ...