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 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 ≤ 100).
Output
Print a single integer — the required sum modulo 1073741824 (230).
Examples
input
2 2 2
output
20
input
5 6 7
output
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,求
#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;
}