首页 > 其他分享 >D. Factorial Divisibility

D. Factorial Divisibility

时间:2022-10-25 17:12:49浏览次数:33  
标签:Divisibility No Factorial a1 int a2 output input

D. Factorial Divisibility time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

You are given an integer xx and an array of integers a1,a2,…,ana1,a2,…,an. You have to determine if the number a1!+a2!+…+an!a1!+a2!+…+an! is divisible by x!x!.

Here k!k! is a factorial of kk — the product of all positive integers less than or equal to kk. For example, 3!=1⋅2⋅3=63!=1⋅2⋅3=6, and 5!=1⋅2⋅3⋅4⋅5=1205!=1⋅2⋅3⋅4⋅5=120.

Input

The first line contains two integers nn and xx (1≤n≤5000001≤n≤500000, 1≤x≤5000001≤x≤500000).

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤x1≤ai≤x) — elements of given array.

Output

In the only line print "Yes" (without quotes) if a1!+a2!+…+an!a1!+a2!+…+an! is divisible by x!x!, and "No" (without quotes) otherwise.

input
6 4
3 2 2 2 3 3
output
Yes
input
8 3
3 2 2 2 2 2 1 1
output
Yes
input
7 8
7 7 7 7 7 7 7
output
No
input
10 5
4 3 2 1 4 3 2 4 3 4
outputCopy
No
input
2 500000
499999 499999
output
No
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N=5e5+10;
int n,x;
map<int,int>p;
int main(){
    cin>>n>>x;
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        p[a]++;//记录每一位的系数 
    }
    for(int i=1;i<=x;i++){
        p[i+1]+=p[i]/(i+1);//逢i+1进1 
        p[i]%=i+1;//得到余数 
    }
    for(int i=1;i<x;i++){
        if(p[i]){//如果有一位不为空则不能整除 
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    
}
/*核心思想
把a!看成一个数的第a位,即转换为进制
如果要想被x!整除,即小于第x位其余位的系数都必须为零,才能被整除
第i位和第i+1位为逢i+1进1*/ 

 

标签:Divisibility,No,Factorial,a1,int,a2,output,input
From: https://www.cnblogs.com/liyiyang/p/16825514.html

相关文章

  • Codeforces Round #829 (Div. 2) D Factorial Divisibility
    FactorialDivisibility模拟合....合成大西瓜?枚举每个阶乘因子,提取公因式之后有很多散着的\(1\),然后判断能不能合成当前倍数#include<iostream>#include<cstdio>#......
  • Codeforces Round #829 (Div. 2) D. Factorial Divisibility(数学)
    题目链接题目大意:\(~~\)给定n个正整数和一个数k,问这n个数的阶乘之和能不能被k的阶乘整除既:(a\(_{1}\)!+a\(_{2}\)!+a\(_{3}\)!+....+a\(_{n}\)!)\(~\)%\(~\)k!\(~\)==......
  • Divisibility by 2^n
    Problem-D-Codeforces题意:给定数列a1,a2,....an令ans=a1*a2*a2*....an每次可以选择一个i(只能选一次),使得ai=ai*i若操作后存在(2^n)|ans,输出最小的操作次数,否则输出-......
  • 洛谷 CF550C Divisibility by Eight(DP/数论)
    遇事不决,小学数学。https://www.luogu.com.cn/problem/CF550C题目大意:给你一个位数不超过100的非负整数N(不含前导0)。你的任务是判断这个数字能否通过去掉其中......
  • Codeforces Round #292 (Div. 2) C. Drazil and Factorial(思维)
    https://codeforces.com/contest/515题目大意:给我们一个长度为n的数字a定义F(a)=a里面每一位数的阶层总乘积让我们求最大的x,需要满足F(x)=f(a)并且x中没有0和1input4......