求质数&分解因式&lcm&整除

1 篇文章 0 订阅
1 篇文章 0 订阅
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1200021;
int cntP[N],isP[N];
int main(){
    ios::sync_with_stdio(false);
    memset(isP,0,sizeof(isP));
    //求质数(if isP[i] = i)
    for(int i = 2;i<N;i++)
        if(!isP[i])
            for(int j = i;j<N;j+=i)
                isP[j] = i;

    //分解质因数,
    int x,xx;cin>>x;xx = x;
    while(x>1){
        cntP[isP[x]]++;
        x/=isP[x];
    }

    //求n个数lcm的因式分解
    int n;cin>>n;
    for(int i = 0;i<n;i++){
        int x;cin>>x;
        while(x>1){//分解质因数,搞成模板才好
            int p = isP[x];
            int cnt = 0;
            while(!(x%p)){
                cnt++;
                x /= p;
            }
            cntP[p] = max(cntP[p],cnt);
        }
    }
    //求n个数的lcm是否整除k
    int k;cin>>k;
    bool ok = 1;
    while(k>1){
        ok &= (cntP[isP[k]]>0);
        cntP[isP[k]]--;
        k/=isP[k];
        if(!ok)break;
    }
    cout<<(ok?"Yes\n":"No\n");

}






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值