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 ...
随机推荐
- Bugku-CTF之输入密码查看flag
Day14 输入密码查看flag http://123.206.87.240:8002/baopo/
- SSM登录跳转到登录页,登录页不能加载js和样式
SSM登录跳转到登录页,登录页不能加载js和样式选用jsppage添加根路径. <% String rootPath = request.getContextPath(); %> < ...
- MyBio小隐本记注册破解
既然开始了,就把这一个系列的都破了算了,这次主角小隐本记MyBio 和WDTP的原理是差不多的,先把软件界面换成e文,然后写了15个记录后提示注册,一样的路子,直接跳过注册窗口的弹出就好了 然后查壳一 ...
- Java线程机制学习
前面的文章中总结过Java中用来解决共享资源竞争导致线程不安全的几种常用方式: synchronized: ReentrantLock: ThreadLocal: 这些都是在简单介绍了基本用法的基础上 ...
- day34 GIL锁 线程队列 线程池
一.Gil锁(Global Interpreter Lock) python全局解释器锁,有了这个锁的存在,python解释器在同一时间内只能让一个进程中的一个线程去执行,这样python的多线程就无 ...
- js中提示框闪退问题
当页面存在刷新 或 在线引用iframe框架时(引用框架也会导致刷新) 会导致页面加载时的弹出框闪退 解决方法:设置弹出框在页面或者框架完全加载一段时间后再弹出 <script type=& ...
- OAF 抛出html消息
throw new oracle.apps.fnd.framework.OAException("<html><p style=\"color:#FF0000; ...
- html5(七) Web存储
http://www.cnblogs.com/stoneniqiu/p/4206796.html http://www.cnblogs.com/v10258/p/3700486.html html5中 ...
- LOJ10155数字转换
题目描述 如果一个数 x 的约数和 y (不包括他本身)比他本身小,那么 x 可以变成 y,y 也可以变成 x.例如 4 可以变为 3,1 可以变为 7.限定所有数字变换在不超过 n 的正整数范围内进 ...
- Linux服务器后门自动化查杀教程
一.说明 如果出现文件上传漏洞和命令执行类漏洞(包括命令注入.缓冲区溢出.反序列化等)都会让人担心,系统是否系统已被上传webshell甚至植入木马程序.如果依靠人工排查,一是工作量大二是需要一定程度 ...