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
time limit per test
 3 seconds
memory limit per test
 512 megabytes
input
 standard input
output
 standard output

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).

Sample test(s)
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.



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();
	}
}






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5407021.html,如需转载请自行联系原作者

相关文章
|
9月前
|
文件存储
Easy Number Challenge(埃式筛思想+优雅暴力)
Easy Number Challenge(埃式筛思想+优雅暴力)
59 0
|
5月前
|
算法
Leetcode 313. Super Ugly Number
题目翻译成中文是『超级丑数』,啥叫丑数?丑数就是素因子只有2,3,5的数,7 14 21不是丑数,因为他们都有7这个素数。 这里的超级丑数只是对丑数的一个扩展,超级丑数的素因子不再仅限于2 3 5,而是由题目给定一个素数数组。与朴素丑数算法相比,只是将素因子变了而已,解法还是和朴素丑数一致的。
64 1
|
5月前
|
存储
Leetcode Single Number II (面试题推荐)
给你一个整数数组,每个元素出现了三次,但只有一个元素出现了一次,让你找出这个数,要求线性的时间复杂度,不使用额外空间。
21 0
LeetCode 136. 只出现一次的数字 Single Number
LeetCode 136. 只出现一次的数字 Single Number
LeetCode contest 177 5169. 日期之间隔几天 Number of Days Between Two Dates
LeetCode contest 177 5169. 日期之间隔几天 Number of Days Between Two Dates
|
算法
LeetCode 414. Third Maximum Number
给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。
66 0
LeetCode 414. Third Maximum Number
|
存储
LeetCode 313. Super Ugly Number
编写一段程序来查找第 n 个超级丑数。 超级丑数是指其所有质因数都是长度为 k 的质数列表 primes 中的正整数。
64 0
LeetCode 313. Super Ugly Number
|
算法
LeetCode 306. Additive Number
累加数是一个字符串,组成它的数字可以形成累加序列。 一个有效的累加序列必须至少包含 3 个数。除了最开始的两个数以外,字符串中的其他数都等于它之前两个数相加的和。 给定一个只包含数字 '0'-'9' 的字符串,编写一个算法来判断给定输入是否是累加数。 说明: 累加序列里的数不会以 0 开头,所以不会出现 1, 2, 03 或者 1, 02, 3 的情况。
88 0
LeetCode 306. Additive Number
|
算法
LeetCode 268. Missing Number
给定一个包含 0, 1, 2, ..., n 中 n 个数的序列,找出 0 .. n 中没有出现在序列中的那个数。
62 0
LeetCode 268. Missing Number