Codeforces 236B Easy Number Challenge 【因子和】

本文介绍了一个关于计算正整数除数数量的问题——Codeforces236B Easy Number Challenge。通过预处理所有可能的除数数量,并利用这些预处理结果来计算特定输入范围内的总和,最后取模1073741824。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:Codeforces 236B Easy Number Challenge

B. Easy Number Challenge
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
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代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <queue>
#define CLR(a, b) memset(a, (b), sizeof(a))
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 1e6 + 1;
const int MOD = 1073741824;
const int INF = 0x3f3f3f3f;
void add(LL &x, LL y) { x += y; x %= MOD; }
int sum[MAXN];
void getsum()
{
    for(int i = 1; i < MAXN; i++) {
        if(i == 1) sum[i] = 1;
        else sum[i] = 2;
    }
    for(int i = 2; i * i < MAXN; i++) {
        for(int j = i; j * i < MAXN; j++) {
            if(i != j) {
                sum[i*j] += 2;
            }
            else {
                sum[i*j] += 1;
            }
        }
    }
}
int main()
{
    getsum();
    int a, b, c;
    while(scanf("%d%d%d", &a, &b, &c) != EOF) {
        LL ans = 0;
        for(int i = 1; i <= a; i++) {
            for(int j = 1; j <= b; j++) {
                for(int k = 1; k <= c; k++) {
                    add(ans, sum[i*j*k]);
                }
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值