『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge

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 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
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值