Description

Saruman’s army of orcs and other dark minions continuously mine and harvest lumber out of the land surrounding his mighty tower for N continuous days. On day number i, Saruman either chooses to spend resources on mining coal and harvesting more lumber, or on raising the level (i.e., height) of his tower. He levels up his tower by one unit only on days where the binary representation of i contains a total number of 1’s that is an exact multiple of 3. Assume that the initial level of his tower on day 0 is zero. For example, Saruman will level up his tower on day 7 (binary 111), next on day 11 (binary 1011) and then day 13, day 14, day 19, and so on. Saruman would like to forecast the level of his tower after N days. Can you write a program to help?

Input

The input file will contain multiple input test cases, each on a single line. Each test case consists of a positive integer N < 1016, as described above. The input ends on end of file.

Output

For each test case, output one line: “Day N: Level = L”, where N is the input N, and L is the number of levels after N days.

Sample Input

2
19
64

Sample Output

Day 2: Level = 0
Day 19: Level = 5
Day 64: Level = 21 这题其实就是一个模拟,其实把n转化为二进制,
然后求出小于等于n有多少个数的二进制中含有1的个数是3的倍数
就是计算组合数,思维题,
例如1000100 当计算到第一个1的时候 就是加上c(6,3)+c(6,6)
此时bits的个数加一,然后到第二个1的时候就是看看
(i+bits)%==0 0<=i<=2 时候存在 i 再加上组合数就是了
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
typedef long long LL;
LL gcd(LL a, LL b ) {
if (b == ) return a;
return gcd(b, a % b);
}
LL combine(LL n, LL r) {
LL ret = ;
if (r > n - r) r = n - r;
for (LL i = ; i <= r ; i++) {
LL k = n - i + ;
LL g = gcd(i, k);
ret = ret / (i / g) * (k / g);
}
return ret;
}
LL ans(LL n) {
LL ret = , bits = , k = ((LL) << ), r = ;
while(k) {
if (k & n) {
for (int i = ; i <= r ; i++) {
if ((i + bits) > && ((i + bits) % == )) ret += combine(r, i);
}
bits++;
}
k = k >> ;
r--;
}
if (bits > && bits % == ) ret++;
return ret;
}
int main() {
LL n;
while(scanf("%lld", &n) != EOF) {
printf("Day %lld: Level = %lld\n", n, ans(n));
}
return ;
}


Saruman’s Level Up~(多校赛算组合数)的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

  3. PKU2018校赛 H题 Safe Upper Bound

    http://poj.openjudge.cn/practice/C18H 题目 算平均数用到公式\[\bar{x}=\frac{x_1+x_2+x_3+\cdots+x_n}{n}\] 但如果用in ...

  4. ZJU 17th 校赛

    第一次参加校赛,和小伙伴们拿了7个气球,还是挺开心的.  简单记个流水账吧. A:判断出INF的情况后 暴力模拟即可. INF的情况有x=1 || y=1 || (x==2 && y= ...

  5. 2017校赛 问题 F: 懒人得多动脑

    题目描述 小D的家A和学校B都恰好在以点F为焦点的双曲线上,而小D每日所需的生活水源在一条平行该双曲线准线的直线上,设它的值为v.大家都知道,每天都是要喝水的,但是小D有点懒,他希望自己能在去上学或者 ...

  6. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  7. 2017CUIT校赛-线上赛

    2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...

  8. HZNU第十二届校赛赛后补题

    愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...

  9. 校赛F

    问题描述 例如对于数列[1 2 3 4 5 6],排序后变为[6 1 5 2 4 3].换句话说,对于一个有序递增的序列a1, a2, a3, ……, an,排序后为an, a1, an-1, a2, ...

随机推荐

  1. ruby 数据类型Number

    Ruby支持的数据类型包括基本的Number.String.Ranges.Symbols,以及true.false和nil这几个特殊值,同时还有两种重要的数据结构——Array和Hash 数值类型(N ...

  2. 最短路径算法 1.Floyed-Warshall算法

    这几周开始正式系统学习图论,新学期开始新的记录.由于二模和生物地理两门高考的临近,时间比较仓促,所以暂时跳过图论的(一)和(二),即图的储存和遍历.从最短路径算法学起,首先要学习的是Floyed-Wa ...

  3. dijkstra算法学习

    dijkstra算法学习 一.最短路径 单源最短路径:计算源点到其他各顶点的最短路径的长度 全局最短路径:图中任意两点的最短路径 Dijkstra.Bellman-Ford.SPFA求单源最短路径 F ...

  4. 基于Ubuntu Server 16.04 LTS版本安装和部署Django之(四):安装MySQL数据库

    基于Ubuntu Server 16.04 LTS版本安装和部署Django之(一):安装Python3-pip和Django 基于Ubuntu Server 16.04 LTS版本安装和部署Djan ...

  5. Linux下中文乱码问题

    记录一下配置centos的时候遇到的一些常见问题 写了一个python脚本,有中文注释,而且会输出一些用户名称,其中包含中文字符.显示的时候出现乱码. 解决方案: 参见博客: Linux基础:中文显示 ...

  6. Python3全栈学习目录

    http://www.cnblogs.com/wupeiqi/articles/4938499.html 文辉整理: http://blog.51cto.com/9272317/1869914

  7. Android TV 开发(3)

    本文来自网易云社区 作者:孙有军   <LinearLayout         android:id="@+id/input_num_line_3"         and ...

  8. 虚拟现实-VR-UE4-创建C++版工程

    首先,创建C++版本的UE4 项目工程,我使用的是4.12.3版本,据了解,新版本后面的编译都是vs2015 所以,想要创建C++版本的工程,就需要安装vs2015 至于vs2015的安装,自己百度吧 ...

  9. AGV系统上位机--工程案例【1】

    1.满足80%系统需求,根据需求生成任务表单 2.指定小车下方任务 3.项目实战应用 4.后台开发,对接其他平台,简易实现自动生成任务列表,自动排单 5.AGV系统上位机初学者很容易理解上手 6.欢迎 ...

  10. ethday04复杂的智能合约

    复杂的智能合约部署和测试 server--database 客户端服务器数据库模式 以太坊dapp应用程序结构 server --- client 模式 server -- database 传统模式 ...