码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2023 牛客国庆day4 【10.2训练补题】


     

    目录

    B-Basic Gcd Problem(素数筛+快速幂)

    H-Harder Gcd Problem(素数)


     B-Basic Gcd Problem(素数筛+快速幂)

    打表找规律发现答案为 (n质因子数目)^c 

    1. #include
    2. using namespace std;
    3. const int N=1e6+5;
    4. typedef long long ll;
    5. typedef unsigned long long ull;
    6. typedef pair<int,int> pi;
    7. const int inf=1<<30;
    8. const ll mod=1e9+7;
    9. inline void read(ll &x){
    10. ll f=1;
    11. x=0;
    12. char ch=getchar();
    13. while(ch<'0'||'9'
    14. if(ch=='-')f=-1;
    15. ch=getchar();
    16. }while('0'<=ch&&ch<='9'){
    17. x=(x<<3)+(x<<1)+(ch&15);
    18. ch=getchar();
    19. }x*=f;
    20. }
    21. ll T,n,c;
    22. int ct[N];
    23. int su[N],cnt;
    24. bool u[N];
    25. void init(){
    26. memset(u,true,sizeof(u));cnt=0;
    27. for(int i=2;i
    28. if(u[i])su[++cnt]=i,ct[i]=1;
    29. for(int j=1;j<=cnt&&su[j]*i
    30. u[su[j]*i]=0;
    31. ct[su[j]*i]=ct[i]+1;
    32. //printf("ct[%d]%d\n",su[i]*j,ct[su[i]*j]);
    33. if(i%su[j]==0)break;
    34. }
    35. }
    36. }
    37. ll quickp(ll b,ll p){
    38. ll res=1;
    39. while(p){
    40. if(p&1)res=res*b%mod;
    41. p>>=1;
    42. b=b*b%mod;
    43. }return res;
    44. }
    45. int main(){
    46. init();
    47. read(T);
    48. while(T--){
    49. read(n);read(c);
    50. printf("%lld\n",quickp(c,ct[n]));
    51. }
    52. return 0;
    53. }

     

    H-Harder Gcd Problem(素数)

    参考题解:

    【2020年牛客暑假第四场】H题 Harder Gcd Problem_2020牛客第四场 h题-CSDN博客

    *所有数字都可由素数与其他数字相乘得到

    *注意 v[ i ]标记时机

    *偶数是素数2的倍数无需特判

    1. #include
    2. using namespace std;
    3. const int N=2e5+5;
    4. typedef long long ll;
    5. typedef unsigned long long ull;
    6. typedef pair<int,int> pi;
    7. const int inf=1<<30;
    8. const ll mod=1e9+7;
    9. inline void read(int &x){
    10. int f=1;
    11. x=0;
    12. char ch=getchar();
    13. while(ch<'0'||'9'
    14. if(ch=='-')f=-1;
    15. ch=getchar();
    16. }while('0'<=ch&&ch<='9'){
    17. x=(x<<3)+(x<<1)+(ch&15);
    18. ch=getchar();
    19. }x*=f;
    20. }
    21. int T,n;
    22. int v[N];
    23. int su[N],cnt;
    24. bool u[N];
    25. void init(){
    26. memset(u,true,sizeof(u));
    27. for(int i=2;i
    28. if(u[i])su[++cnt]=i;
    29. for(int j=1;j<=cnt&&su[j]*i
    30. u[su[j]*i]=0;
    31. if(i%su[j]==0)break;
    32. }
    33. }
    34. }
    35. vectorres;
    36. vector<int>tmp;
    37. int main(){
    38. read(T);
    39. init();
    40. while(T--){
    41. read(n);
    42. for(int i=2;i<=n;i++)v[i]=1;
    43. int ani;
    44. for(int i=1;su[i]*2<=n;i++)ani=i;
    45. for(int i=ani;i>0;i--){
    46. tmp.clear();
    47. for(int j=1;j*su[i]<=n;j++){
    48. int t=j*su[i];
    49. if(v[t]){
    50. tmp.push_back(t);
    51. }
    52. }
    53. int sz=tmp.size();
    54. if(sz&1){
    55. swap(tmp[1],tmp[sz-1]);
    56. }
    57. for(int j=0;j+12){
    58. res.push_back({tmp[j],tmp[j+1]});
    59. v[tmp[j]]=v[tmp[j+1]]=0;
    60. }
    61. }
    62. printf("%d\n",res.size());
    63. for(auto i:res)printf("%d %d\n",i.first,i.second);
    64. res.clear();
    65. }
    66. return 0;
    67. }

  • 相关阅读:
    C认证笔记 - 计算机通识 - 多媒体基础参数
    9. 吴恩达机器学习-推荐系统
    http和https区别与上网过程
    Anaconda 下载安装
    如何制作HTML网页设计【体育运动主题网站——中国篮球NBA】
    Linux C 应用编程学习笔记——(2)文件 I/O 基础
    微服务分布式基于Springcloud的拍卖管理系统597wx
    变量提升的常见情况总结
    41、优惠券秒杀(Redis实现全局唯一id)
    Unity下tga和png格式图片打包成AB包大小和加载速度测试
  • 原文地址:https://blog.csdn.net/m0_63851154/article/details/133522996
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号