• 题意:给你一个数列,求所有子序列对的\(lcm\),然后求这些所有\(lcm\)的\(gcd\).

  • 题解:我们对所有数分解质因数,这里我们首先要知道一个定理:

    ​ 对于\(n\)个数,假如某个质数\(p\),这\(n\)个数中有\(\le n-1\)个数的质因数包含\(p\),那么他们的\(lcm\)中一定不含\(p\)这个因数,随意我们先预处理出每个数的质因子,选择个数\(\ge n-1\)的质因子.

    ​ 然后,在这些质因子中,我们要求每两两之间的\(lcm\),然后再求他们的\(gcd\),不难发现,他们最后得到的\(gcd\)一定是那些\(lcm\)中最小的数,而\(lcm\)最小的数一定是不同次相同底第二小的数(包括1).

    ​ 所以,假如\(p\)的数量为\(n\),那么就选次数第二小的,如果为\(n-1\),就选最小的(因为1肯定比它小).

    ​ 最后,累乘一下就行了.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<long,long> PLL; int n;
    ll x;
    vector<ll> Hash[N];
    void divide(ll x){
    ll cnt=0;
    for(ll i=2;i<=x/i;++i){
    if(x%i==0){
    cnt=0;
    while(x%i==0){
    x/=i;
    cnt++;
    }
    Hash[i].pb(cnt);
    }
    }
    if(x>1) Hash[x].pb(1);
    } ll fpow(ll a,ll k){
    ll res=1;
    while(k){
    if(k&1) res=res*a;
    k>>=1;
    a=a*a;
    }
    return res;
    } int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(ll i=1;i<=n;++i){
    cin>>x;
    divide(x);
    }
    ll ans=1;
    for(ll i=1;i<=200000;++i){
    if(Hash[i].size()>=n-1){
    sort(Hash[i].begin(),Hash[i].end());
    if(Hash[i].size()==n) ans*=fpow(i,Hash[i][1]);
    else ans*=fpow(i,Hash[i][0]);
    }
    }
    printf("%lld\n",ans);
    return 0;
    }

Codeforces #6241 div2 C. Orac and LCM (数学)的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces Round #613 (Div. 2) C. Fadi and LCM (数学)

    题意:给你一个正整数\(x\),找两个正整数\(a\),\(b\),使得\(lcm(a,b)=x\),并且\(max(a,b)\)最小. 题解:我们知道,\(lcm(a,b)=a*b/gcd(a,b) ...

  8. codeforces 356 div2 C.Bear and Prime 100 数学

    C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #641 div2 B. Orac and Models (DP)

    题意:有一个长度为\(n\)的序列\(a\),求一个最长上升子序列,且这个子序列的元素在\(a\)中的位置满足\(i_{j+1}modi_{j}=0\),求这个子序列的最大长度. 题意:这题假如我们用 ...

随机推荐

  1. 不要把file,process或者super权限授予管理员以外的账号

    file权限的主要作用是通过select ....into outfile 写到服务器上具有写权限的目录下,作为文本格式存放,具有权限的目录也就是启动mysql时的用户权限目录.(没有理解) 可以将有 ...

  2. ctfshow—web—web6

    打开靶机 发现登录窗,首先想到SQL注入 抓包,进行SQL注入测试 测试发现空格符被过滤了 使用/**/代替空格符进行绕过,绕过后登录成功 检测回显位 开始查询数据库名 开始查询数据库内数据表名称 查 ...

  3. cmd的终结工具cmder

    常用快捷键 win+alt+t  打开任务设置窗口 win+alt+k 打开快捷键设置窗口 自定义屏幕分割窗口快捷键: ctl+shift+s 水平按50%比例分割 ctl+shift+v 垂直按50 ...

  4. fsutil比较有用的几个命令

    Fsutil:fsinfo 主要由专业支持者使用.列出所有驱动器,查询驱动器类型,查询卷信息,查询特定的 卷信息或文件系统统计信息. 语法参数 drives 列出计算机中所有的驱动器. drivety ...

  5. CMU数据库(15-445)Lab1-BufferPoolManager

    0. 关于环境搭建请看 https://www.cnblogs.com/JayL-zxl/p/14307260.html 1. Task1 LRU REPLACEMENT POLICY 0. 任务描述 ...

  6. Bitter.Core系列 十二 :Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore 之 支持的 where 条件表达式

    Bitter.Core 内置了支持大部分的 linq 的条件表达式.基本上符合我们 where 条件所需.Bitter.Core 的支持 表达式内置  扩展 有: EndsWith    在Sql 解 ...

  7. 【转载】HTTP 协议详细介绍

    背景 当你在浏览器地址栏敲入"http://www.cnblogs.com/",然后猛按回车,呈现在你面前的,将是博客园的首页了(这真是废话,你会认为这是理所当然的).作为一个开发 ...

  8. monitor a local unix domain socket like tcpdump

    Can I monitor a local unix domain socket like tcpdump? - Super User https://superuser.com/questions/ ...

  9. FGC频繁 GC卡顿

    https://mp.weixin.qq.com/s/I1fp89Ib2Na1-vjmjSpsjQ 线上服务的FGC问题排查,看这篇就够了! 原创 骆俊武 IT人的职场进阶 2020-05-10   ...

  10. DPDK CAS(compare and set)操作

    前言 rte_ring是一个无锁队列,无锁队列的出队入队操作是rte_ring实现的关键.因此,本文主要讲解dpdk是怎样使用无锁机制实现rte_ring的多生产者入队操作. rte_atomic32 ...