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的素数去分解的结果有多少个
3 seconds
512 megabytes
standard input
standard output
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).
The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 2000).
Print a single integer — the required sum modulo 1073741824 (230).
2 2 2
20
4 4 4
328
10 10 10
11536
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.
import java.util.*;
public class CF235E {
class Triple {
Triple(){}
Triple(int _x,int _y,int _z) {
this.x=_x; this.y=_y; this.z=_z;
this.sort();
}
public int x,y,z;
void sort() {
if(this.z<this.y) {
int t = this.z;
this.z=this.y;
this.y=t;
}
if(this.z<this.x) {
int t=this.x;
this.x=this.z;
this.z=t;
}
if(this.y<this.x) {
int t=this.x;
this.x=this.y;
this.y=t;
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Triple other = (Triple) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
if (x != other.x)
return false;
if (y != other.y)
return false;
if (z != other.z)
return false;
return true;
}
private CF235E getOuterType() {
return CF235E.this;
}
}
int a,b,c;
final int mod = 1073741824 ;
int[] primes = new int[350];
int pn=0;
boolean[] vis = new boolean[2200];
Map[] map = new Map[333];
void init() {
for(int i=2;i<=2100;i++) {
if(vis[i]==false) {
primes[pn++]=i;
for(int j=2*i;j<=2100;j+=i)
vis[j]=true;
}
}
for(int i=0,j=pn-1;i<=j;i++,j--) {
int t=primes[i];
primes[i]=primes[j];
primes[j]=t;
}
for(int i=0;i<333;i++)
map[i]=new HashMap<Triple,Integer>();
}
long gao(int deep,Triple tri) {
if(deep==pn) return 1;
if(map[deep].get(tri)!=null) return (long) map[deep].get(tri);
long ret=0;
int p=primes[deep];
for(int x=tri.x,i=0;x!=0;x/=p,i++) {
for(int y=tri.y,j=0;y!=0;y/=p,j++) {
for(int z=tri.z,k=0;z!=0;z/=p,k++) {
ret+=gao(deep+1,new Triple(x,y,z))*(i+j+k+1)%mod;
if(ret>=mod) {
ret-=mod;
}
}
}
}
map[deep].put(tri, ret);
return ret;
}
CF235E(){
init();
Scanner in = new Scanner(System.in);
a=in.nextInt(); b=in.nextInt(); c=in.nextInt();
System.out.println(gao(0,new Triple((int)a,(int)b,(int)c)));
}
public static void main(String[] args) {
new CF235E();
}
}
Codeforces 235E. Number Challenge DP的更多相关文章
- Codeforces 235E Number Challenge
http://codeforces.com/contest/235/problem/E 远距离orz......rng_58 证明可以见这里(可能要FQ才能看到) 还是copy一下证明吧: 记 $$f ...
- CodeForces 235E Number Challenge (莫比乌斯反演)
题意:求,其中d(x) 表示 x 的约数个数. 析:其实是一个公式题,要知道一个结论 知道这个结论就好办了. 然后就可以解决这个问题了,优化就是记忆化gcd. 代码如下: #pragma commen ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- Codeforces 251C Number Transformation DP, 记忆化搜索,LCM,广搜
题意及思路:https://blog.csdn.net/bossup/article/details/37076965 代码: #include <bits/stdc++.h> #defi ...
- CF#235E. Number Challenge
传送门 可以理解为上一道题的扩展板.. 然后我们就可以YY出这样一个式子 ${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{ ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- 多校5 HDU5787 K-wolf Number 数位DP
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...
- Codeforces 235E
Codeforces 235E 原题 题目描述:设\(d(n)\)表示\(n\)的因子个数, 给定\(a, b, c\), 求: \[\sum_{i=1}^{a} \sum_{j=1}^{b} \su ...
随机推荐
- Visual Studio 配置 Avalon 自动补全
以VS2013为例: 1.关闭 Visual Studio 2.打开 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Packa ...
- Java基础打包以及批处理命令运行
1.前期准备
- Servlet笔记9--转发与重定向
关于Web中资源跳转的问题: 转发和重定向基本代码: package com.bjpowernode.javaweb; import java.io.IOException; import javax ...
- apache+php windows下配置
2014年1月9日 13:58:54 现在PHP大部分是vc9编译的,其扩展在windows下大部分也都是用vc9编译的(memcache,xdebuge...),,所以要想Apache+PHP+PH ...
- CentOS 5.x 键盘布局改为日语
CentOS 5.x 直接在系统设置界面修改键盘布局,可能不起作用,需要按如下步骤修改配置文件. 1. /etc/sysconfig/keyboard KEYTABLE="jp106&quo ...
- poj1142
分解质因数 #include <iostream> #include <cmath> using namespace std; int sum(int n) { ; ) { a ...
- laravel中redis队列的使用
一.配置文件 首先我们需要在配置文件中配置默认队列驱动为Redis,队列配置文件是config/queue.php: return [ 'default' => env('QUEUE_DRIVE ...
- pyqt5-组件
组件(widgets)是构建一个应用的基础模块.PyQt5有广泛的各式各样的组件,包含:复选按钮(QCheckBox),切换按钮(ToggleButton),滑块条(QSlider),进度条(Prog ...
- spring-cloud-sleuth+zipkin追踪服务实现(四)
1.前言 在上一篇spring-cloud-sleuth+zipkin追踪服务实现(三)的处理实现后,很多朋友告诉我,在zipkin server的管理页面无法看到项目依赖关系. 当时也没有多想,以为 ...
- 镜像文件挂载及本地yum搭建
环境:centos7.2 背景:企业内网不能上网,需安装软件以及软件之间的依赖问题 解决方案:下载和企业内网服务器相同版本的centos7.2镜像文件完整版(不是最小化的iso) 挂载镜像文件 1.上 ...