码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 2020 icpc 南京 K Co-prime Permutation 思维题


    链接:https://ac.nowcoder.com/acm/contest/10272/K?&headNav=acm

    题目描述

    Kotori is very good at math (really?) and she loves playing with permutations and primes.

    One day, she thinks of a special kind of permutation named k co-prime permutation. A permutation p1,p2,⋯ ,pn​ of n is called a k co-prime permutation of n if there exists exactly k integers i such that 1≤i≤n and gcd(pi,i)=1, where gcd(x,y) indicates the greatest common divisor of x and y.

    Given nnn and k, please help Kotori construct a k co-prime permutation of n or just report that there is no such permutation.

    Recall that a permutation of nnn is a sequence of length nnn containing all integers from 1 to n.

    输入描述:

    There is only one test case in each test file.
    
    The first and only line contains two integers n and k (1≤n≤10^6, 0≤k≤n).

    输出描述:

    Output one line containing nnn integers p1,p2,⋯ ,pn separated by one space, indicating the permutation satisfying the given constraints. If no such permutation exists output "-1" (without quotes) instead. If there are multiple valid answers you can print any of them.
    
    Please, DO NOT output extra spaces at the end of each line, otherwise your answer may be considered incorrect!

    示例1

    输入

    5 3

    输出

    1 4 5 2 3

    示例2

    输入

    1 0

    输出

    -1

     题解:思维题 我真是菜 

    让前k个数与下标互质就行了 然后后面的数与下标相同 (两个相同的数是不互质的)

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. using namespace std ;
    8. const int N = 1e6+10;
    9. int n ;
    10. int k ;
    11. int a[N] ;
    12. int main()
    13. {
    14. cin >> n >> k ;
    15. if(k==0) {cout << "-1" ; return 0;}
    16. for(int i = 2 ; i<= k ; i++) a[i-1]=i;
    17. a[k]=1;
    18. for(int i = k+1 ; i<=n ; i++) a[i]=i;
    19. for(int i = 1 ; i <= n ; i++) {
    20. cout << a[i] ;
    21. if( i!= n ) cout << " " ;
    22. }
    23. return 0;
    24. }
  • 相关阅读:
    Nsight Compute 是怎么计算Roofline的呢
    linux系统时钟控制
    阿里8年测试经验,耗时一个月整理的40道自动化测试面试真题(附精准答案解析)足足手写2W字
    SpringBoot 这么实现动态数据源切换,就很丝滑!
    关于智能空气动力学
    Spring Boot实现任意位置的properties及yml文件内容配置与获取
    PLC维护有何难处?如何实现远程维护?
    Java集合框架
    培美曲塞肌白蛋白纳米粒|磺胺地索辛豆清白蛋白纳米粒|茴香酰胺蓖麻蛋白纳米粒(化学品)
    必看!!!客户端requests与服务端request收发请求
  • 原文地址:https://blog.csdn.net/weixin_53439401/article/details/128069011
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号