Codeforces Round #779 B. Marin and Anti-coprime Permutation

B. Marin and Anti-coprime Permutation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ⋅ p 1 ,   2 ⋅ p 2 ,   … ,   n ⋅ p n ) > 1 , \gcd (1 \cdot p_1, \, 2 \cdot p_2, \, \dots, \, n \cdot p_n) > 1, gcd(1p1,2p2,,npn)>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 ≤ 1 0 3 ) (1 \le t \le 10^3) (1t103) — the number of test cases.

Each test case consists of one line containing one integer n ( 1 ≤ n ≤ 1 0 3 ) . n (1 \le n \le 10^3). n(1n103).

Output

For each test case, print one integer — number of beautiful permutations. Because the answer can be very big, please print the answer modulo$ 998,244,353.$

Example

input

Copy

7
1
2
3
4
5
6
1000

output

Copy

0
1
0
4
0
36
665702330

Note

In first test case, we only have one permutation which is [1] but it is not beautiful because gcd ⁡ ( 1 ⋅ 1 ) = 1. \gcd(1 \cdot 1) = 1. gcd(11)=1.

In second test case, we only have one beautiful permutation which is [2, 1] because$ \gcd(1 \cdot 2, 2 \cdot 1) = 2.$

题目分析:

这道题比较巧妙,虽然说只要让gcd不唯一,其实醉酒当的方法就是让gcd为2,也就是全部变成偶数,所以只需要让排列中的奇数乘偶数,偶数乘奇数,这样分配,就能得到数量,如果排列有奇数个数,那么无法让拍列的奇数都成偶数,所以不可能成立,只有排列为偶数个,然后奇数位和偶数位分别求阶乘乘起来就是结果(求阶乘的话,在程序开始前求出来就好,记得取模)

#include<iostream>
using namespace std;
#define mod 998244353
typedef unsigned long long ll;
ll a[504];
int main()
{
    int n;
    cin>>n;
    int tmp;
    a[1]=1;
    for(int i=2;i<=500;i++){
        a[i]=a[i-1]*i%mod;
    }
    while(n--){
        cin>>tmp;
        if(tmp%2!=0)cout<<"0"<<endl;
        else cout<<a[tmp/2]*a[tmp/2]%mod<<endl;
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值