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 ...
随机推荐
- Java-framework-Vaadin
安装vaadin: (1) 首先试了maven+vaadin. 安装maven: 1. unzip apache-maven-3.3.9-bin.zip 2. modify PATH environm ...
- HDU 5402 模拟 构造 Travelling Salesman Problem
题意: 有一个n * m的数字矩阵,每个格子放着一个非负整数,从左上角走到右下角,每个格子最多走一次,问所经过的格子的最大权值之和是多少,并且输出一个路径. 分析: 如果n和m有一个是偶数的话,那么只 ...
- UVa 1452 递推 Jump
约瑟夫变形,先计算出3个数时,最后三个数字的编号. 然后以这三个数为起点,就可以递推出n个数对应的最后三个数字的编号. 递推公式都是一样的. #include <iostream> #in ...
- python socket相关
套接字的工作流程(基于TCP和 UDP两个协议) TCP和UDP对比 TCP(Transmission Control Protocol)可靠的.面向连接的协议(eg:打电话).传输效率低全双工通信( ...
- Android工具 Hierarchy Viewer 分析
Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下,名为hierarchyviewer.bat.它是Android自带的非常有用而且使用简单的工具,可以帮助我 ...
- Ubuntu关机与重启的相关指令
将数据同步写入到磁盘中的指令:sync 惯用的关机指令:shutdown 重新启动,关机:reboot,halt,poweroff shutdown可完成如下工作: 1.可以自由选择关机模式:是要关机 ...
- luogu2564 [SCOI2009]生日礼物
排序枚举左端点,则右端点必定不降 #include <algorithm> #include <iostream> #include <cstring> #incl ...
- FCKeditor自定义编辑区CSS样式
在网站后台使用FCKeditor编辑器的时候,见到的效果可能并不完全是”所见即所得”的,因为如果在FCKeditor编辑区中使用了前台样式表中的样式,在编辑区中并不能把这些样式显示出来.解决这个问题的 ...
- Vue简单了解
目录 1. 前端概览 2. 现代前端开发方式 3. MVVM开发核心 4. Vue核心 5. Vue优点 6. Vue难点 7. Vue与非Vue项目结合 8. Vue调试 9. Vue与SEO 今天 ...
- python学习-- for和if结合使用
for和if结合使用: <h1> {% for i in contents %} {{ i }}{# 注意i也要用两个大括号 #} {% endfor %} </h1> < ...