Codeforces1062D. Fun with Integers(埃氏筛)
题目链接:传送门
题目:
D. Fun with Integers
time limit per test
seconds
memory limit per test
megabytes
input
standard input
output
standard output You are given a positive integer n
greater or equal to . For every pair of integers a and b (≤|a|,|b|≤n), you can transform a into b if and only if there exists an integer x such that <|x| and (a⋅x=b or b⋅x=a), where |x| denotes the absolute value of x . After such a transformation, your score increases by |x|
points and you are not allowed to transform a into b nor b into a anymore. Initially, you have a score of . You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?
Input A single line contains a single integer n
(≤n≤ ) — the given integer described above.
Output Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print .
Examples
Input
Copy Output
Copy Input
Copy Output
Copy Input
Copy Output
Copy Note In the first example, the transformations are →→(−)→(−)→ . In the third example, it is impossible to perform even a single transformation.
思路:
如果一对数a,b可以通过x转换得到分数,那么a→b→-a→-b→a总共可以得到4*|x|的分数。
不妨只考虑0 < a < b,0 < x的情况,把结果乘上4就好了。
此时只能有a*x = b,即b为a的整数倍。对于给定的a,x可以取[2, n/a]范围内的所有值,为一个等差数列。用求和公式计算即可。
代码:
#include <bits/stdc++.h> using namespace std;
typedef long long ll; int main()
{
ll n;
cin >> n;
ll ans = ;
for (ll i = ; i <= n/; i++) {
ll cnt = n/i;
ans += *(+cnt)*(cnt-)/;
}
cout << ans << endl;
return ;
}
Codeforces1062D. Fun with Integers(埃氏筛)的更多相关文章
- CodeForces - 385C Bear and Prime Numbers (埃氏筛的美妙用法)
Recently, the bear started studying data structures and faced the following problem. You are given a ...
- cf1154G 埃氏筛应用
直接用埃氏筛也可以做,但是这题写起来有点恶臭.. 更加简单的写法是直接枚举gcd=k,然后里面再枚举一次i*k,即找到k两个最小的倍数,看起来复杂度很高,但其实也是埃氏筛的复杂度 因为每次枚举gcd, ...
- 「CF779B」「LOJ#10201.」「一本通 6.2 练习 4」Sherlock and His Girlfriend(埃氏筛
题目描述 原题来自:Codeforces Round #400 B. Sherlock 有了一个新女友(这太不像他了!).情人节到了,他想送给女友一些珠宝当做礼物. 他买了 nnn 件珠宝.第 iii ...
- [JXOI 2018] 游戏 解题报告 (组合数+埃氏筛)
interlinkage: https://www.luogu.org/problemnew/show/P4562 description: solution: 注意到$l=1$的时候,$t(p)$就 ...
- 埃氏筛优化(速度堪比欧拉筛) + 洛谷 P3383 线性筛素数 题解
我们一般写的埃氏筛消耗的时间都是欧拉筛的三倍,但是欧拉筛并不好想(对于我这种蒟蒻) 虽然 -- 我 -- 也可以背过模板,但是写个不会的欧拉筛不如写个简单易懂的埃氏筛 于是就有了优化 这个优化还是比较 ...
- 埃氏筛+线段树——cf731F
从2e5-1依次枚举每个数作为主显卡,然后分段求比它大的数的个数,这里的复杂度是调和级数ln2e5,即埃氏筛的复杂度.. #include<bits/stdc++.h> using nam ...
- 数论(8):min_25 筛(扩展埃氏筛)
min_25 筛介绍 我们考虑这样一个问题. \[ans=\sum_{i = 1}^nf(i)\\ \] 其中 \(1 \le n \le 10^{10}\) 其中 \(f(i)\) 是一个奇怪的函数 ...
- U138097 小鱼吃大鱼 埃氏筛
题目描述 小P同学在养殖一种非常凶狠的鱼,而且与其他鱼类不同,这种鱼越大越温顺,反而小鱼最凶残.当两条鱼相遇时, 小鱼会不断撕咬大鱼,每一口都咬下与它自身等重的肉(小鱼保持体重不变),直到大鱼的体重小 ...
- Sirni题解(最小生成树,埃氏筛)(继 Liang-梁)
目录 前言 题意 思路 一些建议 前言 本篇是对Liang-梁的Sirni(最小生成树,埃氏筛)的后继博客. 通篇原文:https://blog.csdn.net/qq_37555704/articl ...
随机推荐
- java的一些基本概念——java11、jdk、jre、jvm等
Java字节码 先介绍下c语言的编译过程,写好代码用编译器(比如gcc)编译过后是机器能够直接执行的二进制机器码. java也类似这种情况,但是java代码文件编译过后不是任何机器都能识别的机器码,而 ...
- Unity_3DText文字显示模糊怎么办
在unity3d中创建一个3d text文字对象模型,但是发现默认情况下显示的文字很模糊,这种情况我们可以通过放大字体尺寸的方式解决这个问题,然后通过缩放的方式改变其大小. 1.打开unity3d场景 ...
- HDFS初次编程
hadoop是用Java语言实现的开源软件框架,可以支持多种语言,我学习的时候用得自然就是Java了. 在开始编程之前需要做一些配置工作: Hadoop开发:Hadoop为HDFS和Mapreduce ...
- Mac配置Hadoop最详细过程
Mac配置Hadoop最详细过程 原文链接: http://www.cnblogs.com/blog5277/p/8565575.html 原文作者: 博客园-曲高终和寡 https://www.cn ...
- 从实验室走向世界:HSP90抑制剂,一种新的癌症药物
热休克蛋白90(HSP90)是细胞内一种普遍存在的.十分保守的以及有高度活性的蛋白质,它在肿瘤细胞内的含量要比正常细胞多.作为一种分子伴侣,HSP90协助不同种类的癌蛋白(即HSP90的服务蛋白)进行 ...
- Hadoop EC 踩坑 :data block 缺失导致的 HDFS 传输速率下降
环境:hadoop-3.0.2 + 11 机集群 + RS-6-3-1024K 的EC策略 状况:某天,往 HDFS 上日常 put 业务数据时,发现传输速率严重下降 分析: 检查集群发现,在之前的传 ...
- vue--一些预设属性
Babel=> 转换工具,将ES6转换成ES5的转换工具.有些浏览器不支持ES6语法: router=> 路由管理器: vueX=> 一个仓库,存储状态信息: CSS pre-pro ...
- js实现千位分隔
最近一个项目中使用到了千位分隔这个功能,在网上也看见一些例子,但是实现起来总觉有些复杂.因此,自己实现了一个千位分隔,留给后来的我们. 先上源码吧. 该方法支持传入的是一个数字字符串,数字.第二个参数 ...
- 天地图常用WMTS配置参数
wmts常用参数 var matrixIds = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', ...
- linux内核升级5.0
升级内核$ rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org$ rpm -Uvh http://www.elrepo.org/elr ...