Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C#, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
Cho số nguyên dương N, liệt tính tổng ước của tất cả các số từ 1 tới N và in ra màn hình.
Đầu vào
- Số nguyên N
Giới hạn
- 1≤N≤10^6
Đầu ra
- In ra tổng ước của các số từ 1 tới N
Ví dụ :
Input 01
12
Output 01
1 3 4 7 6 12 8 15 13 18 12 28
Bình luận
Python thì tui chịu chết rồi qua c++ zậy
include <iostream>
include <vector>
using i64 = long long;
std::vector<i64> sievesumdivisors(int n) { std::vector<i64> sumdiv(n + 1, 0); for (int i = 1; i <= n; ++i) for (int j = i; j <= n; j += i) sumdiv[j] += i; return sum_div; }
void printresult(const std::vector<i64>& data, std::ostream& out) { for (sizet i = 1; i < data.size(); ++i) out << data[i] << '\n'; }
int main() { std::ios::syncwithstdio(false); std::cin.tie(nullptr);
}
Ai cứu tui phát tui optimaze hết khả năng rồi vẫn bị lỗi quá thời gian của case 31->40
import sys from collections import defaultdict input = sys.stdin.readline
def solve(): n = int(input()) res = defaultdict(int) for i in range(1, n + 1): for j in range(i, n + 1, i): res[j] += i output = [] for i in range(1, n + 1): output.append(str(res[i])) sys.stdout.write(' '.join(output) + '\n')
solve() res = array('L', [1] * (n + 1)) for i in range(2, n + 1): for j in range(i, n + 1, i): res[j] += i print(' '.join(map(str, res[1:])))
solve()