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 ...
随机推荐
- 面向对象的封装(私有化)及@property(查看)/@setter(修改)!!!
面向对象有三大特性,继承,多态,封装继承可以减少代码重复量,多态可以用多继承模仿别的语言的建立规则约束子类封装为类的属性/方法的私有化,可以限制别人看,读,修改的权限,目前理解做记录,日后温习,回顾, ...
- hadoop MR的一些文件归属(包括临时文件存储情况)
https://blog.csdn.net/bxyz1203/article/details/8057810
- jQuery validator plugin之Methods
step method Makes the element require a given step. step( value ) value Type: Number Step value requ ...
- Learning-Python【15】:内置函数
截止到Python版本3.6.2,一共为我们提供了68个内置函数.它们就是Python提供的直接可以拿来使用的所有函数. 这个表的顺序是按照首字母的排列顺序来的,都混乱的堆在一起.比如,oct和bin ...
- [转载]C++之路起航——标准模板库(deque)
转自:https://www.cnblogs.com/grhyxzc/p/5074061.html deque(双端队列):http://baike.baidu.com/link?url=JTvA2c ...
- 使用C#加密及解密字符串
using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Util ...
- 微生物组学数据分析工具综述 | 16S+宏基因组+宏病毒组+宏转录组--转载
转载:https://mp.weixin.qq.com/s/xsL9GuLs7b3nRF8VeRtinQ 建立在高通量测序基础上的微生物群落研究,当前主要有三大类:基于16S/18S/ITS等扩增子做 ...
- selenium + firefox驱动版本对应。
1)selenium 2.51.0====firefox 46 selenium 3.11.0 ====firefox 56 后来发现最新的火狐浏览器好多插件都不能用了.所以果断回到46.对应的2.5 ...
- java 常见语法,但是发现switch等基础,常见面试套路不会了,待补充
1,面向对象,万物皆对象,面向对象的三个基本特性:封 装,继承,多态. 面向对象的程序都是由类组成,类封装了对象的属性和行为. 封装:隐藏对象的属性和实现细节,仅对外提供接口. 继承:实现代码复用,将 ...
- JAVA中经过nginx反向代理获取客户端ip并获取相关坐标等信息
关于搜狐新浪ip库查询接口的使用 直接输出访客ip及所在城市: <script src="http://pv.sohu.com/cityjson?ie=utf-8" > ...