我是靠谱客的博主 糟糕苗条,这篇文章主要介绍CodeForce 236B Easy Number Challenge(筛法求素数 + 整数因式分解),现在分享给大家,希望可以做个参考。

题目链接:http://codeforces.com/problemset/problem/236/B
Easy Number Challenge
time limit per test
2 seconds
memory limit per test
256 megabytes

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

Output

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

Examples
input
复制代码
1
2 2 2
output
复制代码
1
20
input
复制代码
1
5 6 7
output
复制代码
1
1520
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.


题意:首先定义d(x)表示x的因子个数。然后给出三个正整数a、b、c,求
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdio> #include <iostream> #include <cstring> #include <set> #include <cmath> using namespace std; typedef long long LL; const int Mod = 1073741824; int prime[1000000], vis[10000050]; int pri_cnt; void get_prime() { // 筛法求素数 int m = (int)sqrt(100000 + 1); pri_cnt = 0; memset(vis, 0, sizeof(vis)); vis[0] = 1; vis[1] = 1; for(int i = 2; i <= m; ++i) { if(!vis[i]) { prime[pri_cnt++] = i; for(int j = i * i; j <= 1000005;j += i) vis[j] = 1; } } } int get_cnt(int x) { // 求x的因数有多少个 if(x == 1) return 1; if(!vis[x]) return 2; int ans = 1; for(int i = 0; x != 1 && i < pri_cnt; ++i) { int cnt = 0; while(x % prime[i] == 0) { cnt++; x /= prime[i]; } ans = ans * (cnt + 1); } return ans; } int main() { get_prime(); int a, b, c; while(~scanf("%d%d%d", &a, &b, &c)) { int ans = 0; for(int i = 1; i <= a; ++i) { for(int j = 1; j <= b; ++j) { for(int k = 1; k <= c; ++k) { ans = (ans + get_cnt(i * j * k)) % Mod; } } } printf("%dn", ans); } return 0; }


最后

以上就是糟糕苗条最近收集整理的关于CodeForce 236B Easy Number Challenge(筛法求素数 + 整数因式分解)的全部内容,更多相关CodeForce内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(87)

评论列表共有 0 条评论

立即
投稿
返回
顶部