sdut 3257 Cube number

来源:互联网 发布:知乎电脑版下载官网 编辑:程序博客网 时间:2024/05/18 03:07

Cube Number

Time Limit: 2000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

In mathematics, a cube number is an integer that is the cube of an integer. In other words, it is the product of some integer with itself twice. For example, 27 is a cube number, since it can be written as 3 * 3 * 3. 
Given an array of distinct integers (a1, a2, ..., an), you need to find the number of pairs (ai, aj) that satisfy (ai * aj) is a cube number.
 

输入

 The first line of the input contains an integer T (1 ≤ T ≤ 20) which means the number of test cases. 
Then T lines follow, each line starts with a number N (1 ≤ N ≤ 100000), then N integers followed (all the integers are between 1 and 1000000).
 

输出

 For each test case, you should output the answer of each case.

示例输入

1   5   1 2 3 4 9

示例输出

2

提示

 

来源

 

示例程序

 

  • 提交 
  • 状态 
  • 讨论
    • 上一道题的扩展
      我们可以发现如果A*B 为一个立方数的话 那么他们质因子分解 中每个质因子的个数要是3的倍数
      ACcode:
      #pragma warning(disable:4786)//使命名长度不受限制#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈#include <map>#include <set>#include <queue>#include <cmath>#include <stack>#include <cctype>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d,&x,&y,&z)#define rdl(x) scanf("%I64d,&x);#define rds(x) scanf("%s",x)#define rdc(x) scanf("%c",&x)#define ll long long int#define ull unsigned long long#define maxn 1000100#define mod 1000000007#define INF 0x3f3f3f3f //int 最大值#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define MT(x,i) memset(x,i,sizeof(x))#define PI  acos(-1.0)#define E  exp(1)#define eps 1e-8ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}ll mul(ll a,ll b,ll p){ll sum=0;for(;b;a=(a+a)%p,b>>=1)if(b&1)sum=(sum+a)%p;return sum;}inline void Scan(int &x) {      char c;while((c=getchar())<'0' || c>'9');x=c-'0';      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';}using namespace std;int prime[maxn];int dp[66];int vis[maxn];int dpp[222];void init(){    memset(prime,0,sizeof(prime));    for(int i=2;i<=maxn;++i){        if(!prime[i])prime[++prime[0]]=i;        for(int j=1;j<=prime[0]&&prime[j]<=maxn/i;j++){            prime[prime[j]*i]=1;            if(i%prime[j]==0)break;        }    }    memset(dpp,0,sizeof(dpp));    for(int i=1;i<=200;++i)        dpp[i]=prime[i]*prime[i];    for(int i=1;i<=60;++i)        dp[i]=prime[i]*prime[i]*prime[i];}int main(){    int n,loop,cnt=1;    init();    scanf("%d",&loop);    while(loop--){        Scan(n);        memset(vis,0,sizeof(vis));        int ans=0;        for(int i=0;i<n;++i){            int t;            cin>>t;            for(int j=1;j<=60;++j)                if(t%dp[j]!=0)continue;                else while(t%dp[j]==0)t/=dp[j];            vis[t]++;            if(t==1){                ans+=(vis[t]-1);                continue;            }            int tmp=1;             for(int j=1;j<=199;++j)                if(t%dpp[j]!=0)continue;                else while(t%dpp[j]==0){tmp*=dpp[j];t/=dpp[j];}            if(t<=1000){                t=sqrt(tmp)*t*t;                if(t<maxn)                ans+=vis[t];            }        }        printf("%d\n",ans);    }    return 0;}/*751 2 3 4 931 2 471 2 3 4 5 6 782 34123 344 35 33 23 434232 123 1234 3361 4 9 16 25 3661 8 64 27 125 216*/


0 0
原创粉丝点击