当前位置:网站首页>十九届浙大城院程序设计竞赛 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;
}
边栏推荐
- D - I Hate Non-integer Number(背包dp)
- The obstacles to put Istio into production and how we solve them
- A Beginner's Guide to Performance Testing
- PAT1166 Summit(25)
- SAP ABAP OData 服务如何支持创建(Create)操作试读版
- Why does the maximum plus one equal the minimum
- fh511小风扇主控芯片 便携式小风扇专用8脚IC 三档小风扇升压芯片sop8
- 动态库、静态库浅析
- 魔众短链接系统 v3.9.0
- 数据挖掘-04
猜你喜欢
随机推荐
JMP Pro 16.0 software installation package download and installation tutorial
使用ffmpeg来查看视频的信息,fps,和width,height
CCS软件安装教程(超级详细)「建议收藏」
嵌入式开发:创建和使用可移植类型的7个技巧
How does the SAP ABAP OData service support the Create operation trial version
Efficiency tools to let programmers get off work earlier
求方阵的无穷范数「建议收藏」
观察者模式
全球都热炸了,谷歌服务器已经崩掉了
shell 中的 分发系统 expect脚本 (传递参数、自动同步文件、指定host和要传输的文件、(构建文件分发系统)(命令批量执行))
Based on 10 years of experience in stability assurance, what are the three key questions to be answered in failure recovery?|TakinTalks big coffee sharing
leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】
SQL function SQRT
【无标题】
fh511小风扇主控芯片 便携式小风扇专用8脚IC 三档小风扇升压芯片sop8
iPhone难卖,被欧洲反垄断的服务业务也难赚钱了,苹果的日子艰难
AtCoder Beginner Contest 261 D - Flipping and Bonus
207.数组序号转换
PAT1166 Summit(25)
高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能











