当前位置:网站首页>3588. Permutation and binary
3588. Permutation and binary
2022-07-28 15:13:00 【Pursue people far away】

In combinatorics , We learned permutation numbers .
from n Take out... Of the different elements m(m<=n) The number of all permutations of elements , It's called from n To take m Number of permutations of , Write it down as p(n,m).
The specific calculation method is p(n,m)=n(n−1)(n−2)……(n−m+1)=n!/(n−m)!( Regulations 0!=1).
When n and m Not very young , This permutation number is a relatively large number , such as p(10,5)=30240.
If expressed in binary, it is p(10,5)=30240=(111011000100000)b, in other words , At the back 5 A zero .
Our problem is , Given a permutation number , Calculate the number of consecutive zeros following its binary representation .
Input format
Input contains multiple sets of test data .
Each group of data occupies one row , Contains two integers n,m.
Last act 0 0, End of input , No need to deal with .
Output format
Output one row per group of data , A result , Represents the permutation number p(n,m) The binary representation of is followed by how many consecutive zeros .
Data range
1≤m≤n≤10000,
The input can contain at most 100 Group data .
sample input :
10 5
6 1
0 0
sample output :
5
1

Code :
// How many are there at the end of binary 0 <==> Decomposing prime numbers 2 What is the index of
#include <bits/stdc++.h>
using namespace std;
int n, m;
int f(int n, int p) // n How many factorials are there p Multiply Find the number
{
int res = 0;
while (n)
res += n / p, n /= p;
return res;
}
int main()
{
int n, m;
while (cin >> n >> m, n)
{
cout << f(n, 2) - f(n - m, 2) << endl;
}
return 0;
}
边栏推荐
- Development status of security and privacy computing in China
- Chapter I Introduction
- 手摸手实现Canal如何接入MySQL实现数据写操作监听
- Introduction to mqtt protocol
- Shell command
- Mlx90640 infrared thermal imager sensor module development notes (VIII)
- Compose learning notes 1-compose, state, flow, remember
- charles如何安装并使用
- Talk about low code / zero code tools
- MLX90640 红外热成像仪传感器模块开发笔记(八)
猜你喜欢
随机推荐
3588. 排列与二进制
模板注入总结
企业微信客服链接,企业微信客服聊天
3564. 日期类
Keras reported an error using tensorboard: cannot stop profiling
8、 C scope rules
Find papers and their open source code
Basic operation implementation of sequence table
回编译失败
buuctf_ php
17、 Solutions to duplicate names of ROS function packages and nodes
使用cpolar发布树莓派网页(apache2的安装测试)
Rocky基础之修改网卡名为eth0
The first self introduction quotation
Repvgg paper explanation and model reproduction using pytoch
4518. 最低票价
3511. Water pouring problem
从thinkphp远程代码执行学php反射类
No files or folders found to process
Development status of security and privacy computing in China









