CF840C.On the Bench

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that a__p__i·a__p__i + 1 is not perfect square, holds. Leha wants to find number of right permutations modulo 109 + 7.

一年前,Leha 在公园的长椅上发现了一个包含 nn 个数字的数组。Leha 认为一个排列 pp 是“合法的”,当且仅当对所有 1≤i<n1 \le i < n,均满足 api⋅api+1a_{p_i} \cdot a_{p_{i+1}} 不是一个完全平方数。Leha 想要求出合法排列的个数,并对 109+710^9 + 7 取模。

输入格式

First line of input data contains single integer n (1 ≤ n ≤ 300) — length of the array.

Next line contains n integers _a_1, _a_2, ... , a__n (1 ≤ a__i ≤ 109) — found array.

输入数据的第一行包含一个整数 nn(1 ≤ n ≤ 3001 \leq n \leq 300)—— 数组的长度。

第二行包含 nn 个整数 a1, a2, …, ana_1, a_2, \dots, a_n(1 ≤ ai ≤ 1091 \leq a_i \leq 10^9)—— 所给定的数组。

输出格式

Output single integer — number of right permutations modulo 109 + 7.

输出一个整数——满足条件的排列数目对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    3
    1 2 4

    输出#1

    2
  • 输入#2

    7
    5 2 4 2 4 1 1

    输出#2

    144

说明/提示

For first example:

[1, 2, 4] — right permutation, because 2 and 8 are not perfect squares.

[1, 4, 2] — wrong permutation, because 4 is square of 2.

[2, 1, 4] — wrong permutation, because 4 is square of 2.

[2, 4, 1] — wrong permutation, because 4 is square of 2.

[4, 1, 2] — wrong permutation, because 4 is square of 2.

[4, 2, 1] — right permutation, because 8 and 2 are not perfect squares.

第一个例子:

[1, 2, 4] — 正确的排列,因为 2 和 8 都不是完全平方数。

[1, 4, 2] — 错误的排列,因为 4 是 2 的平方。

[2, 1, 4] — 错误的排列,因为 4 是 2 的平方。

[2, 4, 1] — 错误的排列,因为 4 是 2 的平方。

[4, 1, 2] — 错误的排列,因为 4 是 2 的平方。

[4, 2, 1] — 正确的排列,因为 8 和 2 都不是完全平方数。

输入解题思路,AI测评打分。不知道怎么写?

首页