All submissions for this problem are available.

Read problems statements in Mandarin Chinese and Russian.

This problem's statement is really a short one.

You are given an integer S. Consider an infinite sequence S, 2S, 3S, ... . Find the first number in this sequence that can be represented as Q3, where Q is some positive integer number. As the sought number could be very large, please print modulo (109 + 7).

The number S will be given to you as a product of N positive integer numbers A1, A2, ..., AN, namely S = A1 * A2 * ... * AN

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.

The first line of each test case contains an integer N.

Then there is a line, containing N space separated integers, denoting the numbers A1, A2, ..., AN.

Output

For each test case, output a single line containing the first term of the sequence which is the perfect cube, modulo 109+7.

Constraints

  • 1T10
  • (Subtask 1): N = 1, 1S109 - 15 points.
  • (Subtask 2): N = 1, 1S1018 - 31 point.
  • (Subtask 3): 1N100, 1Ai1018 - 54 points.

Example

Input:
2
2
2 2
2
2 3
Output:
8
216

Explanation

Example case 1. First few numbers in the infinite sequence 4, 8, 12, 16, 20, , etc. In this sequence, 8 is the first number which is also a cube (as 23 = 8).

Example case 2. First few numbers in the infinite sequence 6, 12, 18, 24, , etc. In this sequence, 216 is the first number which is also a cube (as 63 = 216).

【分析】

挺模板的东西,就当复习一下了。

 /*
宋代李冠
《蝶恋花·春暮》
遥夜亭皋闲信步。
才过清明,渐觉伤春暮。
数点雨声风约住。朦胧淡月云来去。
桃杏依稀香暗渡。
谁在秋千,笑里轻轻语。
一寸相思千万绪。人间没个安排处。
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#define LOCAL
const int MAXN = + ;
const long long MOD = ;
const double Pi = acos(-1.0);
long long G = ;//原根
const int MAXM = * + ;
using namespace std;
typedef long long ll;
ll read(){
ll flag = , x = ;
char ch;
ch = getchar();
while (ch < '' || ch > '') {if (ch == '-') flag = -; ch = getchar();}
while (ch >= '' && ch <= '') {x = x * + (ch - ''); ch = getchar();}
return x * flag;
}
map<ll, int>Num;//记录个数
ll data[MAXN];
ll n; ll mul(ll a, ll b, ll c){//又要用快速乘QAQ
if (b == ) return 0ll;
if (b == ) return a % c;
ll tmp = mul(a, b / , c);
if (b % == ) return (tmp + tmp) % c;
else return (((tmp + tmp) % c) + (a % c)) % c;
}
ll pow(ll a, ll b, ll c){
if (b == ) return 1ll;
if (b == ) return a % c;
ll tmp = pow(a, b / , c);
if (b % == ) return mul(tmp, tmp, c);
else return mul(mul(tmp, tmp, c), a, c);
}
bool Sec_check(ll a, ll b, ll c){
ll tmp = pow(a, b, c);
if (tmp != && tmp != (c - )) return ;
if (tmp == (c - ) || (b % != )) return ;
return Sec_check(a, b / , c);
}
//判断n是否是素数
bool miller_rabin(ll n){
int cnt = ;
while (cnt--){
ll a = (ll)rand() % (n - ) + ;
if (!Sec_check(a, n - , n)) return ;
}
return ;
}
ll gcd(ll a, ll b){return b == 0ll ? a : gcd(b, a % b);}
ll pollard_rho(ll a, ll c){
ll i = , k = ;
ll x, y, d;
x = (ll)((double)(rand() / RAND_MAX) * (a - ) + 0.5) + 1ll;
y = x;
while (){
i++;
x = (mul(x, x, a) % a + c) % a;
d = gcd(y - x + a, a);
if (d > && d < a) return d;
if (y == x) return a;//失败
if (i == k){
k <<= ;
y = x;
}
}
}
void find(ll a, ll c){
if (a == ) return;
if (miller_rabin(a)){
Num[a]++;
return;
}
ll p = a;
while (p >= a) pollard_rho(a, c--);
pollard_rho(p, c);
pollard_rho(a / p, c);
}
void init(){
Num.clear();
scanf("%d", &n);
for (int i = ; i <= n; i++) {
data[i] = read();
find(data[i], );
}
}
void work(){
ll Ans = ;
for (int i = ; i <= n; i++) Ans = (Ans * data[i]) % MOD;
for (map<ll, int>::iterator it = Num.begin(); it != Num.end(); it++){
it->second %= ;
if (it->second){
for (int i = it->second; i < ; i++) Ans = (Ans * ((it->first) % MOD)) % MOD;
}
}
printf("%lld\n", Ans);
} int main(){
int T; scanf("%d", &T);
while (T--){
init();
work();
}
return ;
}

【CODECHEF】【phollard rho + miller_rabin】The First Cube的更多相关文章

  1. 最短路(模板)【CodeChef CLIQUED,洛谷P3371】

    自TG滚粗后咕咕咕了这么久,最近重新开始学OI,也会慢慢开始更博了.... 最短路算法经典的就是SPFA(Bellman-Ford),Dijkstra,Floyd: 本期先讲两个经典的单源最短路算法: ...

  2. 【CodeChef】Querying on a Grid(分治,最短路)

    [CodeChef]Querying on a Grid(分治,最短路) 题面 Vjudge CodeChef 题解 考虑分治处理这个问题,每次取一个\(mid\),对于\(mid\)上的三个点构建最 ...

  3. 【CodeChef】Palindromeness(回文树)

    [CodeChef]Palindromeness(回文树) 题面 Vjudge CodeChef 中文版题面 题解 构建回文树,现在的问题就是要求出当前回文串节点的长度的一半的那个回文串所代表的节点 ...

  4. HDU1164_Eddy&#39;s research I【Miller Rabin素数测试】【Pollar Rho整数分解】

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. 【CodeChef】Find a special connected block - CONNECT(斯坦纳树)

    [CodeChef]Find a special connected block - CONNECT(斯坦纳树) 题面 Vjudge 题解 还是一样的套路题,把每个数字映射到\([0,K)\)的整数, ...

  6. 【OpenCV入门教程之十四】OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑

    http://blog.csdn.net/poem_qianmo/article/details/26977557 本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog ...

  7. 【OpenCV新手教程之十四】OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/26977557 作者:毛星云(浅墨) ...

  8. 【Knockout.js 学习体验之旅】(3)模板绑定

    本文是[Knockout.js 学习体验之旅]系列文章的第3篇,所有demo均基于目前knockout.js的最新版本(3.4.0).小茄才识有限,文中若有不当之处,还望大家指出. 目录: [Knoc ...

  9. 【Knockout.js 学习体验之旅】(2)花式捆绑

    本文是[Knockout.js 学习体验之旅]系列文章的第2篇,所有demo均基于目前knockout.js的最新版本(3.4.0).小茄才识有限,文中若有不当之处,还望大家指出. 目录: [Knoc ...

随机推荐

  1. Spout数据源

    Spout 数据源 消息源 Spout 是 Storm 的 Topology 中的消息生产者(即 Tuple 的创造者). Spout 介绍 1. Spout 的结构 Spout 是 Storm 的核 ...

  2. 学习并使用了两种linq to entity 的实现sql关键字in的查询方法

    //构造Lambda语句        private static Expression<Func<TElement, bool>> BuildWhereInExpressi ...

  3. SmartbBear给出的11条代码审查最佳实践

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:SmartbBear给出的11条代码审查最佳实践.

  4. Java实现文件的RSA和DES加密算法

    根据密钥类型不同将现代密码技术分为两类:对称加密算法(秘密钥匙加密)和非对称加密算法(公开密钥加密) 对称钥匙加密系统是加密和解密均采用同一把秘密钥匙,而且通信双方都必须获得这把钥匙,并保持钥匙的秘密 ...

  5. 1.关于UltraEdit中的FTP和Tenent配置,UE远程连接Linux进行文件操作

     1  安装UltraEdit 2  配置FTP相关的配置 文件àFTP/Tenet(T)à watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3 ...

  6. mysql 5.6 oom 图

  7. debian安装mono环境

    官网 http://pkg-mono.alioth.debian.org/ 在/etc/apt/sources.list 加上 deb http://debian.meebey.net/pkg-mon ...

  8. UVA 10564 - Paths through the Hourglass (dp)

    本文出自   http://blog.csdn.net/shuangde800 题目传送门 题意: 给一个相上面的图.要求从第一层走到最下面一层,只能往左下或右下走,经过的数字之和为sum. 问有多少 ...

  9. 【转】BeagleBone Black USB一线通(3)

    接上篇  BeagleBone Black 一线通(2) 五.vnc图形终端 虽然 BB-Black带有一个Micro-HDMI接口,不过那么名片不到的一个小板,连接到一个20来寸的显示器上,还是有些 ...

  10. linux安装java环境

    在linux下安装JDK如下: 第一步:查看Linux自带的JDK是否已安装 (1)查看已经安装的jdk: [root@web-server ~]# rpm -qa|grep jdk ← 查看jdk的 ...