当前位置:网站首页>十九届浙大城院程序设计竞赛 F.Sum of Numerators(数学/找规律)
十九届浙大城院程序设计竞赛 F.Sum of Numerators(数学/找规律)
2022-08-01 13:48:00 【Curz酥】
题目链接 https://ac.nowcoder.com/acm/contest/31533/F
![]()
示例1
输入
2 5 0 5 1输出
15 12
解析:
数学思维题。枚举结果来找规律,然后利用等差数列求和公式来求出结果。
C++代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int t, n, k, res;
cin >> t;
while(t--){
cin >> n >> k;
res = n * (n + 1) / 2; //先用等差数列求和公式求出总和
while(n and k){
n /= 2; //会被约分的数字个数每次都是总长的一半
--k; //每次被约分,2的次数减一
res -= (n * (n + 1) / 2); //找规律,可知每次被约分掉的总和是 等差数列求1到被约分掉的数字个数之和
}
cout << res << "\n";
}
return 0;
}
边栏推荐
- 性能测试入门指南
- 响应式2022英文企业官网源码,感觉挺有创意的
- PIR人体感应AC系列感应器投光灯人体感应开关等应用定制方案
- D - I Hate Non-integer Number(背包dp)
- OpenSSL SSL_read: Connection was reset, errno 10054
- Why does the maximum plus one equal the minimum
- A Beginner's Guide to Performance Testing
- PAT1165 Block Reversing(25)
- Two Permutations
- How to integrate 3rd party service center registration into Istio?
猜你喜欢

PAT 1163 Dijkstra Sequence(30)

OpenSSL SSL_read: Connection was reset, errno 10054

【无标题】

观察者模式

树和二叉树的转换

gpio analog serial communication

芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)

JMP Pro 16.0 software installation package download and installation tutorial

程序员的浪漫七夕

论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
随机推荐
线上问题排查常用命令,总结太全了,建议收藏!!
AtCoder Beginner Contest 261 D - Flipping and Bonus
A Beginner's Guide to Performance Testing
The basic knowledge of scripting language Lua summary
CCS软件安装教程(超级详细)「建议收藏」
Grafana 9.0 released, Prometheus and Loki query builders, new navigation, heatmap panels and more!
分布式中的CAP原理
为什么最大值加一等于最小值
Istio投入生产的障碍以及如何解决这些问题
ABC260 E - At Least One (Dual Pointer)
sql is not null 优化(oracle语句索引优化)
全链路灰度在数据库上我们是怎么做的?
微服务原生案例搭建
What Can Service Mesh Learn from SDN?
论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
六石编程学:问题要面对,办法要技巧,做不好的功能要想办法
【码蹄集新手村600题】判断一个数字是否为完全平方数
windows IDEA + PHP+xdebug 断点调试
软件测试之发现和解决bug
多线程案例——定时器

