51Nod-1586-约数和
来源:互联网 发布:淘宝介入卖家能赢吗 编辑:程序博客网 时间:2024/06/06 12:35
ACM模版
描述
题解
为什么我感觉这个题加不加输入输出外挂没啥两样呢?都是
先预处理一下每个数的约数个数,然后直接暴力就好了。
代码
#include <cstdio>using namespace std;typedef long long ll;const int MAXN = 1e6 + 10;int n, q;int cnt[MAXN];ll a[MAXN];template <class T>inline void scan_d(T &ret){ char c; ret = 0; while ((c = getchar()) < '0' || c > '9'); while (c >= '0' && c <= '9') { ret = ret * 10 + (c - '0'), c = getchar(); }}template <class T>inline void print_d(T x){ if (x > 9) { print_d(x / 10); } putchar(x % 10 + '0');}int main(){ scan_d(n), scan_d(q); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { cnt[j]++; } } int odr, x, y; while (q--) { scan_d(odr); if (odr == 1) { scan_d(x), scan_d(y); for (int i = x, j = 1; i <= n; i += x, j++) { a[i] += y * cnt[j]; } } else { scan_d(x); print_d(a[x]); putchar(10); } } return 0;}
阅读全文
0 0
- 51nod 1586 约数和
- 51nod 1586 约数和
- 51Nod 1586 约数和
- 51Nod-1586-约数和
- 51nod 1586 约数和
- [杜教筛 约数和前缀和] 51Nod 1220 约数之和
- 【51nod】【算法马拉松14】1586 约数和
- 51nod 1584 加权约数和
- 51nod 1584 加权约数和
- 51Nod-1220-约数之和
- 51nod 1220 约数之和
- 51nod 1220 约数之和
- [莫比乌斯反演] 51Nod 1584 加权约数和
- 51nod1584 加权约数和
- 约数个数及约数和
- PE 439 Sum of sum of divisors | 51nod 1220 约数之和
- 51nod oj 1116 【进制问题】 1179【约数打表】
- 51nod 1165 整边直角三角形的数量 【数学:公式--求约数】
- 数据结构之数组 笔记
- Android开发系列之浅浅谈Intent
- 跳台阶
- Spring声明式事务管理踩过
- POJ 1386 欧拉路径判断
- 51Nod-1586-约数和
- JS获取当前日期指定天后的日期
- 记录一次前端系统调优过程,针对于页面卡顿
- 【剑指Offer】:变态跳台阶
- Thrift之java实例
- Python快速入门(6)- 类
- 淘淘商城业务--加油
- 简单工厂
- 设计模式