sdut 3257 Cube number
2016-05-20 20:00
369 查看
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-8 ll 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; } /* 7 5 1 2 3 4 9 3 1 2 4 7 1 2 3 4 5 6 7 8 2 34 123 344 35 33 23 43 4 232 123 1234 33 6 1 4 9 16 25 36 6 1 8 64 27 125 216 */
相关文章推荐
- 多线程技术(三)
- 【bzoj 2393】Cirno的完美算数教室
- HashMap和HashSet的区别
- 字典树典型应用(1247)
- const char **ptr 与 char *ptr[] 的释放问题的探究
- MySQL入门--显示指定数据表的字段结构、插入指定字段的值(记录)、查看指定表中指定字段的所有记录
- 索尼Z2(L50t)刷CM12教程
- BZOJ 4553: [Tjoi2016&Heoi2016]序列
- 从Eclipse转移到IntelliJ IDEA的一点心得
- 用c++实现单向链表和双向链表
- Office10安装提示:Microsoft Office 2010 安装要求您的计算机上安装 MSXML 版本 6.10.1129.0
- 图像配准】基于灰度的模板匹配算法(一):MAD、SAD、SSD、MSD、NCC、SSDA、SATD算法
- Android之ListView优化基本
- Linux_2_Navigation
- 内容模式
- querySelectorAll对象无ID的题
- Wolf and Rabbit (hdu_1222) 欧几里德
- 【IPC通信】有名管道FIFO
- [No000097]程序员面试题集【下】
- django ajax 应用实例