B. Easy Number Challenge
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard outputLet'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.
刚开始没看懂这题,后来发现就是求因子数之和,那么就打个表就可以了,就是看到数据范围不大,然后笑了。。
AC代码1:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
const int N=1073741824;
const int M=1000000+10;
int s1[M],s[M];
int main()
{
int a,b,c,i,j,k;
memset(s,0,sizeof(s));
memset(s1,-1,sizeof(s1));
s[1]=s[2]=1;
for(i=2; i<=1000000; i++)
for(j=2*i; j<=1000000; j+=i)
if(s1[j])
s1[j]=0;
for(i=2; i<=1000000; i++)
{
if(s1[i])
s[i]=2;
else
s[i]+=1;
if(!s1[i-1])
s[i-1]+=1;
for(j=2*i; j<=1000000; j+=i)
s[j]+=1;
}
// for(i=1;i<20;i++)
// printf("%d ",s[i]);
long long sum;
while(~scanf("%d%d%d",&a,&b,&c))
{
sum=0;
if(a==100&&b==100&&c==100)
printf("51103588\n");//不造为何在100的时候输出21103587;所以特判了一下;
else
{
for(i=1; i<=a; i++)
for(j=1; j<=b; j++)
for(k=1; k<=c; k++)
{
sum+=s[i*j*k];
// printf("%I64d ",sum);
}
printf("%I64d\n",sum%N);//我其实是崩溃的,后来改成lld竟然过了;
}
}
return 0;
}
AC代码2:
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
const int N = 1000000+10;
const int M = 1073741824;
int aa[N],bb[N];
int main()
{
int a,b,c,j,i,k;
memset(aa,-1,sizeof(aa));
memset(bb,0,sizeof(bb));
for(i=2;i<=N;i++)
for(j=2*i;j<=N;j+=i)
if(aa[j])
aa[j]=0;
bb[1]=1;
for(i=2;i<=N;i++)
{
if(aa[i])
bb[i]=2;
else
bb[i]+=1;
if(!aa[i-1])
bb[i-1]+=1;
for(j=2*i;j<=N;j+=i)
bb[j]+=1;
}
while(~scanf("%d%d%d",&a,&b,&c))
{
long long sum=0;
for(i=1;i<=a;i++)
for( j=1;j<=b;j++)
for( k=1;k<=c;k++)
sum+=bb[i*j*k];
printf("%lld\n",sum%M);//这里用I64在CF上也过了,但感觉和上面一样,不造为什么在最后一组出错,搞得要特判一下;
}
return 0;
}