Sum of Numerators
Sum of Numerators
题目链接
学习资料
题意:给定n,k;每一项ai/2k约分后, ∑ \sum ∑分子。
假设n = 8,k = 2;
初始分子:
1 2 3 4 5 6 7 8
res = (1+8) * 8 / 2 = 36
第一轮约分后:
1 1 3 2 5 3 7 4
[1-n]之间的偶数都减半
res -= (1+4) * 4/ 2 =26
第二轮约分后:
1 1 3 1 5 3 7 2
[1-n/2]之间的偶数都减半
res -= (1+2) * 2 / 2 = 23
直到!n || !k 截止;
Code:
int T;
int main() {cin >> T;while(T--) {ll n,k;cin>>n>>k;ll sum = (1+n)*n/2;while(n&&k) {n>>=1;k--;sum -= (1+n)*n/2;}cout<<sum<<endl;}return 0;
}
题目变式:
可以每一项都除以3k,4k…做法同理
逆水行舟,不进则退~
Sum of Numerators相关推荐
- [GYM103660] The 19th Zhejiang University City College Programming Contest 浙大城市学院校赛VP/S
后面俩小时吃饭睡觉去了- A B C D E F G H I J K L AC AC AC 补 补 AC AC AC AC AC – AC GYM103660A.Who is The 19th ZUC ...
- 【十九届浙大城市学院程序设计竞赛 - 周训】
Who is The 19th ZUCCPC Champion Jiubei and Overwatch Ah, It's Yesterday Once More Sum of Numerators ...
- 第十九届浙大城市学院程序设计竞赛
I.Array Division 数组分组,要求每组的和大于等于0,求最多可以分成几组. #include<bits/stdc++.h>using namespace std;#defin ...
- 1081 Rational Sum (20 分)_22行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given N rational numbers in the form numerator/denominator, you a ...
- 1081. Rational Sum (20) -最大公约数
题目如下: Given N rational numbers in the form "numerator/denominator", you are supposed to ca ...
- 1081. Rational Sum (20)-PAT甲级真题
Given N rational numbers in the form "numerator/denominator", you are supposed to calculat ...
- 【PAT】Rational Sum
题目描述 Given N rational numbers in the form "numerator/denominator", you are supposed to cal ...
- 1081 Rational Sum (20 分) 分数加法 简单模拟
1081 Rational Sum (20 分) Given N rational numbers in the form numerator/denominator, you are suppose ...
- go build 编译报错 missing go.sum entry for module providing package
go build 编译报错 missing go.sum entry for module providing package 解决方法 // 移除未使用的依赖 go mod tidy 再次编译,就可 ...
最新文章
- 【sublime Text】sublime Text3安装可以使xml格式化的插件
- 打桥位lisp_lisp函数
- Python之多进程
- 小白的算法初识课堂(part1)--二分查找法
- sonar 代理_Sonar
- 今天看到导师给我的批注哭了...
- Java hibernate假外键_浅谈hibernate急迫加载问题(多重外键关联)
- Python入门--列表,字典,元组,集合总结
- Windows Mobile如何得到资源文件中的文件
- 全世界云计算宕机和中断[2013年-2014年集锦]
- devc ++的安装教程(C语言学习比较好用的一个开发软件)
- libevent实现TCP 客户端
- boobooke播布客
- js实现鼠标移动到div背景颜色变换,移开还原
- C/C++实现刮刮乐-刮奖区,刮出一套房
- 运维:你们 JAVA 服务怎么又又又又出问题了,内存降不下来。
- 惊蛰时节,最好看的微信公众号图文排版,全在这里了
- 11.8号软基2.2.2
- 将SQL server2019数据库部署在虚拟机上
- html5自动播放mov格式视频