码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • A. Perfect Permutation


    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    You are given a positive integer nn.

    The weight of a permutation p1,p2,…,pnp1,p2,…,pn is the number of indices 1≤i≤n1≤i≤n such that ii divides pipi. Find a permutation p1,p2,…,pnp1,p2,…,pn with the minimum possible weight (among all permutations of length nn).

    A permutation is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041≤t≤104). The description of the test cases follows.

    The only line of each test case contains a single integer nn (1≤n≤1051≤n≤105) — the length of permutation.

    It is guaranteed that the sum of nn over all test cases does not exceed 105105.

    Output

    For each test case, print a line containing nn integers p1,p2,…,pnp1,p2,…,pn so that the permutation pp has the minimum possible weight.

    If there are several possible answers, you can print any of them.

    Example

    input

    Copy

     
    

    2

    1

    4

    output

    Copy

    1
    2 1 4 3
    

    Note

    In the first test case, the only valid permutation is p=[1]p=[1]. Its weight is 11.

    In the second test case, one possible answer is the permutation p=[2,1,4,3]p=[2,1,4,3]. One can check that 11 divides p1p1 and ii does not divide pipi for i=2,3,4i=2,3,4, so the weight of this permutation is 11. It is impossible to find a permutation of length 44 with a strictly smaller weight.

    解题说明:水题,只需要找出一种结果,把n放到最前面即可。

    1. #include
    2. int main()
    3. {
    4. int tc;
    5. scanf("%d", &tc);
    6. while (tc--)
    7. {
    8. int n;
    9. scanf("%d", &n);
    10. printf("%d", n);
    11. for (int i = 1; i < n; i++)
    12. {
    13. printf(" %d", i);
    14. }
    15. printf("\n");
    16. }
    17. return 0;
    18. }

  • 相关阅读:
    12 【操作mongodb数据库】
    利用机器学习应对气候变化
    Java回顾-集合-Map-HashMap/LinkedHashMap/TreeSet/Properties
    基于springboot+Thymeleaf的校园二手交易平台(附源码获取链接)
    【21天学习挑战赛】快速排序
    【服务器数据恢复】HP StorageWorks系列服务器RAID5两块盘离线的数据恢复
    思派健康通过上市聆讯:半年亏损约35亿元,马旭广为董事长
    【STM32】STM32学习笔记-修改主频 睡眠模式 停止模式 待机模式(45)
    微信小程序顶部tab切换
    面试总结-单例模式之Java实现
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/127974190
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号