当前位置:网站首页>Permutation and binary (Ji, DA) (day 84)
Permutation and binary (Ji, DA) (day 84)
2022-07-27 03:40:00 【Zhangxueheng】
List of articles
1: subject
ji Lin Big xue Computer test questions
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
difficulty : Simple
when / Empty limit :1s / 64MB
Total number of passes :681
Total attempts :1047
source : Jilin University postgraduate entrance examination machine test questions
Algorithm tags
2: Code implementation
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int f(int n, int p)
{
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;
}
边栏推荐
- spark学习笔记(五)——sparkcore核心编程-RDD转换算子
- [1206. Design skip table]
- Docker creates MySQL 8.x container and supports Mac and arm architecture chips
- 代码审查金字塔
- spark学习笔记(四)——sparkcore核心编程-RDD
- 复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别
- Debug mode in pycharm for detailed debugging
- 客户案例 | 关注老年用户体验,银行APP适老化改造要避虚就实
- [common search questions] 111
- [learning notes, dog learning C] string + memory function
猜你喜欢

Spark: calculate the average value of the same key in different partitions (entry level - simple implementation)

spark学习笔记(五)——sparkcore核心编程-RDD转换算子

客户案例 | 关注老年用户体验,银行APP适老化改造要避虚就实

Code review pyramid

Spark Learning Notes (V) -- spark core core programming RDD conversion operator

Double disk: the main differences between DFS and BFS, the differences in ideology, and the differences in code implementation

Fastboot刷机

The application and significance of digital twins are the main role and conceptual value of electric power.

Number of 0 at the end of factorial

MySQL underlying data structure
随机推荐
[learn FPGA programming from scratch -54]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Altera)
Learn the recycling mechanism of recyclerview again
若依的环境的部署以及系统的运行
FastBoot brush machine
[untitled] JDBC connection database read timeout
How many implementation postures of delay queue? Daily essential skills!
Fastboot刷机
Reading notes of Kazuo Inamori's advice to young people
OC message mechanism
常见弱口令大全
Deployment of ruoyi's environment and operation of the system
[common search questions] 111
flask_restful中reqparse解析器继承
数据库概论 - MySQL的简单介绍
The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
volatile关键字及其作用
How can you access the domestic server and overseas server quickly with one database?
Introduction to redis
Banyan loan,
智能体重秤方案主控采用CSU18M91