码农知识堂 - 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. }
  • 相关阅读:
    git--修改用户名和邮箱的方法(全局修改和局部修改)
    css 实现文字流光效果
    学会 Python 自动安装第三方库,从此跟pip说拜拜
    Day696.Jetty如何实现具有上下文信息的责任链 -深入拆解 Tomcat & Jetty
    企业是否需要单独一套设备管理系统?
    【Linux-Linux发展史和环境安装】开源的力量!
    18-Java迭代器模式 ( Iterator Pattern )
    学习《Java核心技术》——第6章:接口、lambda表达式与内部类
    关于Google推出的AAB,你了解多少
    CNN记录】pytorch中flatten函数
  • 原文地址:https://blog.csdn.net/weixin_53439401/article/details/128069011
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号