CodeForce 236B Easy Number Challenge(筛法求素数 + 整数因式分解)
生活随笔
收集整理的这篇文章主要介绍了
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
题意:首先定义d(x)表示x的因子个数。然后给出三个正整数a、b、c,求 #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("%d\n", ans);}return 0; }
与50位技术专家面对面20年技术见证,附赠技术全景图
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).
InputThe first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 100).
OutputPrint a single integer — the required sum modulo 1073741824 (230).
Examples input 2 2 2 output 20 input 5 6 7 output 1520 NoteFor 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,求 #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("%d\n", ans);}return 0; }
与50位技术专家面对面20年技术见证,附赠技术全景图
总结
以上是生活随笔为你收集整理的CodeForce 236B Easy Number Challenge(筛法求素数 + 整数因式分解)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: CodeForce 237C Prime
- 下一篇: 你和高级开发的距离,可能还缺这个技术框架