列表

详情


NC25105. [USACO 2006 Ope l]Bedtime Reading

描述

Farmer John was performing his nightly bedtime reading duties for Bessie. "Oh, this gives me a headache," moaned Bessie.
"But it's just simple number theory," replied FJ. "Let's go over it again. The sigma function of a number is just the sum of the divisors of the number. So, for a number like 12, the divisors are 1, 2, 3, 4, 6, and 12. Summing them we get 28."
"That's all there is to it?" asked Bessie.
"Yep." replied FJ. "Perhaps someone will write a program to calculate the sigma function of an integer I (1 <= I <= 1,000,000)."

输入描述

Line 1: A single integer, I

输出描述

Line 1: The sum of all of I's divisors.

示例1

输入:

12

输出:

28

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 7ms, 内存消耗: 448K, 提交时间: 2023-05-15 16:34:39

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int I;int sum=0;
    cin>>I;
    for(int i=1;i<=I;i++){
        if(I%i==0){sum=sum+i;}
    }
    cout<<sum;
    return 0;
}

上一题