Zhu and 772002
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 396 Accepted Submission(s): 121
Total Submission(s): 396 Accepted Submission(s): 121
Problem Description
Zhu and 772002 are both good at math. One day, Zhu wants to test the ability of 772002, so he asks 772002 to solve a math problem.
But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.
There are n numbers a1,a2,...,an . The value of the prime factors of each number does not exceed 2000 , you can choose at least one number and multiply them, then you can get a number b .
How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007 .
But 772002 has a appointment with his girl friend. So 772002 gives this problem to you.
There are n numbers a1,a2,...,an . The value of the prime factors of each number does not exceed 2000 , you can choose at least one number and multiply them, then you can get a number b .
How many different ways of choices can make b is a perfect square number. The answer maybe too large, so you should output the answer modulo by 1000000007 .
Input
First line is a positive integer
T
, represents there are
T
test cases.
For each test case:
First line includes a number n(1≤n≤300) ,next line there are n numbers a1,a2,...,an,(1≤ai≤1018) .
For each test case:
First line includes a number n(1≤n≤300) ,next line there are n numbers a1,a2,...,an,(1≤ai≤1018) .
Output
For the i-th test case , first output Case #i: in a single line.
Then output the answer of i-th test case modulo by 1000000007 .
Then output the answer of i-th test case modulo by 1000000007 .
Sample Input
2 3 3 3 4 3 2 2 2
Sample Output
Case #1: 3 Case #2: 3
Author
UESTC
Source
2016中国大学生程序设计竞赛 - 网络选拔赛
和uva 11542 一样 看那个博客吧!
只是数据稍微大了一点,思路还是一样的!
听说学长在取模上有坑,可能是在乘的时候不小心爆了。。
因为要取模,所以可以写个快速幂,这样可以解决溢出问题!
和uva 11542 一样 看那个博客吧!
只是数据稍微大了一点,思路还是一样的!
听说学长在取模上有坑,可能是在乘的时候不小心爆了。。
因为要取模,所以可以写个快速幂,这样可以解决溢出问题!
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 5;
const int mod = 1000000007;
int equ, var;
int a[maxn][maxn];
int x[maxn];
int free_x[maxn];
int free_num;
int vis[maxn];
vector<int >prime;
int len_prime;
ll my_pow(ll a,ll n){
ll ans = 1;
while(n){
if (n & 1)
ans = (ans % mod * a % mod) % mod;
n/=2;
a = (a%mod*a%mod)%mod;
}
return ans;
}
int Gauss(){
int max_r,col,k;
free_num = 0;
for (k = 0, col = 0; k < equ && col < var; k++, col++){
max_r = k;
for (int i = k+1; i < equ; i++){
if (abs(a[i][col]) > abs(a[max_r][col]))
max_r = i;
}
if (a[max_r][col] == 0){
k--;
free_x[free_num++] = col;
continue;
}
if (max_r != k){
for (int j = col; j < var+1; j++)
swap(a[k][j],a[max_r][j]);
}
for (int i = k+1; i < equ; i++){
if (a[i][col] != 0){
for (int j = col; j < var+1; j++)
a[i][j] ^= a[k][j];
}
}
}
for (int i = k; i < equ; i++)
if (a[i][col] != 0)
return -1;
if (k < var)return var- k;
for (int i = var-1; i >= 0; --i){
x[i] = a[i][var];
for (int j = i+1; j < var; j++)
x[i] ^= (a[i][j] && x[j]);
}
return 0;
}
void init(){
int len = sqrt(maxn) + 1;
for (int i = 2; i <= len; ++i) if (!vis[i])
for (int j = i*i; j < maxn; j+=i) vis[j] = 1;
for (int i = 2; i < maxn; ++i)if (!vis[i])prime.push_back(i);
len_prime = (int)prime.size();
}
int main(){
init();
int T,kase = 0;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
memset(a,0,sizeof a);
for (int i = 0; i < n; ++i){
ll x;
scanf("%I64d",&x);
for (int j = 0; j < len_prime; ++j){
int pri = prime[j];
while(x % pri == 0){
a[j][i] ^= 1;
x/=pri;
}
if (x == 1)break;
}
}
equ = len_prime;
var = n;
int t = Gauss();
printf("Case #%d:\n",++kase);
printf("%I64d\n",my_pow(2ll,(ll)t)-1ll);
}
return 0;
}