当前位置:网站首页>Find the combination number acwing 888 Find the combination number IV
Find the combination number acwing 888 Find the combination number IV
2022-07-05 06:24:00 【T_ Y_ F666】
Find the combination number AcWing 888. Find the combination number IV
Original link
AcWing 888. Find the combination number IV
Algorithm tags
Combinatorial mathematics Combination count High precision
Ideas
Code
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 5015;
int pr[N], st[N], s[N], cnt;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
void pri(int n){
rep(i, 2, n+1){
if(!st[i]){
pr[cnt++]=i;
}
for(int j=0; pr[j]<=n/i; ++j){
st[pr[j]*i]=true;
if(!(i%pr[j])){
break;
}
}
}
}
int get(int n, int p){
int res=0;
while(n){
res+=n/p;
n/=p;
}
return res;
}
vector<int> mul(vector<int> a, int b){
vector<int> c;
int t=0;
rep(i, 0, a.size()){
t+=a[i]*b;
c.push_back(t%10);
t/=10;
}
while(t){
c.push_back(t%10);
t/=10;
}
return c;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a=read(), b=read();
pri(a);
rep(i, 0, cnt){
int p=pr[i];
s[i]=get(a, p)-get(a-b, p)-get(b, p);
}
vector<int> res;
res.push_back(1);
rep(i, 0, cnt){
rep(j, 0, s[i]){
res=mul(res, pr[i]);
}
}
Rep(i, res.size()-1, 0){
printf("%lld", res[i]);
}
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- 11-gorm-v2-03-basic query
- LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
- There are three kinds of SQL connections: internal connection, external connection and cross connection
- Nested method, calculation attribute is not applicable, use methods
- LeetCode-61
- Golang uses context gracefully
- Leetcode-6109: number of people who know secrets
- 11-gorm-v2-02-create data
- ollvm编译出现的问题纪录
- 博弈论 AcWing 894. 拆分-Nim游戏
猜你喜欢
2021apmcm post game Summary - edge detection
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
Day 2 document
5.Oracle-錶空間
1.14 - assembly line
7.Oracle-表结构
MySQL advanced part 1: View
There are three kinds of SQL connections: internal connection, external connection and cross connection
背包问题 AcWing 9. 分组背包问题
随机推荐
Leetcode-6110: number of incremental paths in the grid graph
Leetcode-9: palindromes
[BMZCTF-pwn] ectf-2014 seddit
Is it impossible for lamda to wake up?
区间问题 AcWing 906. 区间分组
Chart. JS - Format Y axis - chart js - Formatting Y axis
[leetcode] day95 effective Sudoku & matrix zeroing
LeetCode-54
11-gorm-v2-02-create data
[moviepy] unable to find a solution for exe
什么是套接字?Socket基本介绍
MySQL advanced part 1: triggers
Chapter 6 relational database theory
栈 AcWing 3302. 表达式求值
Leetcode stack related
ollvm编译出现的问题纪录
TypeScript 基础讲解
[rust notes] 16 input and output (Part 1)
[rust notes] 17 concurrent (Part 1)
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out