Codeforces:1658B Marin and Anti-coprime Permutation题解

Marin wants you to count number of permutations that are beautiful. A beautiful permutation of length n is a permutation that has the following property:
gcd(1⋅p1,2⋅p2,…,n⋅pn)>1,
where gcd is the greatest common divisor.

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

Input
The first line contains one integer t (1≤t≤103) — the number of test cases.

Each test case consists of one line containing one integer n (1≤n≤103).

Output
For each test case, print one integer — number of beautiful permutations. Because the answer can be very big, please print the answer modulo 998244353.

输入输出
7
10
21
30
44
50
636
1000665702330

分析:当n为奇数时,permutations的数量为0
当n为偶数时,permutations的数量为pow((n/2)!,2)
感叹号为阶层

		例子:n=6    A(3,3)*A(3,3)=36
		即排列组合n/2的偶数位3个与n/2的奇数位3个排列组合

原因:当n为偶数时gcd(1 * p1, 2 * p2…n * pn)
p1,p3,p5…只能放偶数
p2,p4,p6…只能放奇数
此时 p11,p22,p3*3 全为偶数
最大公约数为2


import java.util.Scanner;


public class Main {
    public static void main(String[] args)  {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        for (int i=0;i<t;i++)
        {
            int n=in.nextInt();
            if ((n&1)==1)//为奇数
            {
                System.out.println(0);
            }
            else
            {
            	//n除以2
                n=n/2;
                long sum=1l;
                for (int j=2;j<=n;j++)//n/2
                {
                    sum=sum*j*j%998244353;
                }
                System.out.println(sum);
            }
        }

    }
}

求赞

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值