• 题意:给你一个数列,求所有子序列对的\(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肯定比它小).

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

  • 代码:

    1. #include <iostream>
    2. #include <cstdio>
    3. #include <cstring>
    4. #include <cmath>
    5. #include <algorithm>
    6. #include <stack>
    7. #include <queue>
    8. #include <vector>
    9. #include <map>
    10. #include <set>
    11. #include <unordered_set>
    12. #include <unordered_map>
    13. #define ll long long
    14. #define fi first
    15. #define se second
    16. #define pb push_back
    17. #define me memset
    18. const int N = 1e6 + 10;
    19. const int mod = 1e9 + 7;
    20. using namespace std;
    21. typedef pair<int,int> PII;
    22. typedef pair<long,long> PLL;
    23. int n;
    24. ll x;
    25. vector<ll> Hash[N];
    26. void divide(ll x){
    27. ll cnt=0;
    28. for(ll i=2;i<=x/i;++i){
    29. if(x%i==0){
    30. cnt=0;
    31. while(x%i==0){
    32. x/=i;
    33. cnt++;
    34. }
    35. Hash[i].pb(cnt);
    36. }
    37. }
    38. if(x>1) Hash[x].pb(1);
    39. }
    40. ll fpow(ll a,ll k){
    41. ll res=1;
    42. while(k){
    43. if(k&1) res=res*a;
    44. k>>=1;
    45. a=a*a;
    46. }
    47. return res;
    48. }
    49. int main() {
    50. ios::sync_with_stdio(false);
    51. cin>>n;
    52. for(ll i=1;i<=n;++i){
    53. cin>>x;
    54. divide(x);
    55. }
    56. ll ans=1;
    57. for(ll i=1;i<=200000;++i){
    58. if(Hash[i].size()>=n-1){
    59. sort(Hash[i].begin(),Hash[i].end());
    60. if(Hash[i].size()==n) ans*=fpow(i,Hash[i][1]);
    61. else ans*=fpow(i,Hash[i][0]);
    62. }
    63. }
    64. printf("%lld\n",ans);
    65. return 0;
    66. }

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. 用js实现打印九九乘法表

    用js在打印九九乘法表 思考 在学习了流程控制和条件判断后,我们可以利用js打印各式各样的九九乘法表 不管是打印什么样三角形九九乘法表,我们都应该找到有规律的地方,比如第一列的数字是什么规律,第一行的 ...

  2. Tomcat-8 安装和配置

    JDK 安装: # 选择版本: yum list all | grep jdk # 安装openjdk-1.8.0: yum install java-1.8.0-openjdk.x86_64 -y ...

  3. redis持久化怎么选?成年人从来不做选择...

    前言 面试官:你知道 redis 是的怎么做持久化的吗? 我:我知道 redis 有两种方式,一种是 RDB,一种是 AOF. 面试官:那这两种方式具体是怎么做的,它们的区别是什么,生产环境中到底应该 ...

  4. linux网络工具nc命令

    nc是netcat的简写,有着网络界的瑞士军刀美誉.因为它短小精悍.功能实用,被设计为一个简单.可靠的网络工具. nc命令的作用 (1)实现任意TCP/UDP端口的侦听,nc可以作为server以TC ...

  5. [从源码学设计]蚂蚁金服SOFARegistry之延迟操作

    [从源码学设计]蚂蚁金服SOFARegistry之延迟操作 0x00 摘要 SOFARegistry 是蚂蚁金服开源的一个生产级.高时效.高可用的服务注册中心. 本系列文章重点在于分析设计和架构,即利 ...

  6. ichartjs插件的使用

    项目中可能会用到饼状图.柱状图.环形图等,ichartjs是一个很不错的插件,体量小,只需引入ichart.1.2.1.min.js即可满足基础需求,github下载地址是:https://githu ...

  7. uni-app 获取地址位置

    uni.getLocation 获取当前的地理位置.速度. 在微信小程序中,当用户离开应用后,此接口无法调用:当用户点击"显示在聊天顶部"时,此接口可继续调用 uni.getLoc ...

  8. mysql(视图 事务 索引 外键)

    视图   视图本质就是对查询的封装   创建视图(定义视图 起名以v_开头) create view v_students as select classes.name as c_name ,stud ...

  9. 两个报文是如何进行 TCP 分组传输

    16 | 如何理解TCP的"流"? https://time.geekbang.org/column/article/132443 TCP 是一种流式协议在前面的章节中,我们讲的都 ...

  10. (Oracle)关于blob转到目标库报ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值错误解决方案

    在数据抽取时,开发需要clob类型的数据,但是目标库类型是blob类型的,于是抽取的时候报错: ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值错误 可能有以下几种原因: 可能有以下 ...