B. Easy Number Challenge
time limit per test
2 seconds
memory limit per test
256 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 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
Copy
2 2 2
output
20
input
Copy
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.
题意:
给三个数,求出三个数所有组合的乘积拥有的因子个数之和。
思路:
a,b,c都不超过100,暴力解决,算法核心是找出因子个数。那么要如何求出因子个数呢?
首先要明白:对于一个整数x,所有x的倍数都含有x这个因子(有一种逆素数筛的感觉是吧)。知道这个,这道题就解了一大半了。
#include<bits/stdc++.h>
/*#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>
#include<vector>
#include<map>
#include<queue>*/
#define LL long long
#define inf 0x7f7f7f7f
const int N=1e6;//因为a,b,c最大就100,那范围就跑不出100*100*100
using namespace std;
long long s[N];//s[i]表示整数i的因子个数
//核心:生成因数表
void f()
{
for(int i=1;i<=N+1;i++)
for(int j=i;j<=N+1;j+=i)//j始终为i的倍数
s[j]++;
}
int main()
{
int a,b,c;
cin>>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+=s[i*j*k];//找到因子个数加起来就是答案了
}
cout<<ans;
}