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 ...
随机推荐
- MATLAB raw格式转为bmp格式
今天是第一天写博客,哈哈哈!把完成的数字图像作业放上来和大家一起分享一下! 如果有什么问题,希望大家和我多多交流 1518234852@qq.com width=512; height=512; im ...
- ERROR 1666 (HY000): Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.
centos7.5 binlog恢复数据失败 问题: mysql> \. /tmp/inc.sql ERROR 1050 (42S01): Table 'new_1' already exist ...
- 网站基础html javascript jquery
第二章HTML HBuilder的使用 边改边看模式 chrome浏览器看. HTML的基本格式 超文本标记语言 HyperText Markup Language HyperText 超文本 Mar ...
- Spring错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
背景:学习切面,测试前置通知功能,xml配置如下 <?xml version="1.0" encoding="UTF-8"?> <beans ...
- 【CentOS 7】CentOS7与CentOS6 的区别
前言 centos7与6之间最大的差别就是初始化技术的不同,7采用的初始化技术是Systemd,并行的运行方式,除了这一点之外,服务启动.开机启动文件.网络命令方面等等,都说6有所不同. 一.系统初始 ...
- Architectural principles
原文 "If builders built buildings the way programmers wrote programs, then the first woodpecker t ...
- Go语言学习之10 Web开发与Mysql数据库
本节主要内容: 1. http编程2. mysql使用 1. http编程 (1)http编程分析 Go原生支持http,import(“net/http”) Go的http服务性能和nginx比较接 ...
- springboot aop 不生效原因解决
最近参照资料创建Springboot AOP ,结果运行后aop死活不生效. 查明原因: 是我在创建AOP类时选择了Aspect类型,创建后才把这个文件改为Class类型,导致一直不生效, 代码配置这 ...
- C#执行EXE程序
第一种方法:System.Diagnostics.ProcessStartInfo info =new System.Diagnostics.ProcessStartInfo(path);info.W ...
- 打造springboot高性能服务器(spring reactor的使用)
推荐:https://www.cnblogs.com/ivaneye/p/5731432.htmlpom依赖: <dependency> <groupId>org.spring ...