【map】【分解质因数】CDOJ1572 Espec1al Triple
先把公比为1,即前项 中项 末项相同的统计出来。对每一类数C(n,3)即可。
然后我们发现,因为a1*a3=(a2)^2,所以a1和a3进行质因子分解之后,每一个质因子的指数的奇偶性必然相同,否则无法满足乘积为完全平方数。
然后sqrt(100000)以内的素数只有65个,我们对于每一个数,用unsigned long long存一个01串,代表前64个素因子的奇偶性,再单独用一个布尔存第65个。
然后该数还有可能有一个大素因子(>sqrt(x)),单独存一下,这样用一个三元组唯一标示每一个数。
a1和a3的三元组必然完全相同。
于是对于这样一个三元组,开个map套vector记录下符合其的数的个数(不超过log个),然后就很容易统计了。
复杂度其实很低,就是常数挺大。
#include<cstdio>
#include<bitset>
#include<map>
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
struct Point{
ull S;
int x;
int y;
Point (const ull &A,const int &X,const int &Y){
S=A;
x=X;
y=Y;
}
Point(){ }
};
bool operator < (const Point &a,const Point &b){
if(a.S!=b.S){
return a.S<b.S;
}
if(a.x!=b.x){
return a.x<b.x;
}
return a.y<b.y;
}
map<Point,vector<int> >ma;
ll ans;
bool vis[100000];
int pri[1000],pr;
void shai(){
vis[1]=1;
for(int i=1;i*i<=100000;++i){
if(!vis[i]){
pri[pr++]=i;
for(int j=i*i;j*j<=100000;j+=i){
vis[j]=1;
}
}
}
}
int n,m,a[1000010];
ll num[100010];
int main(){
// freopen("e.in","r",stdin);
shai();
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
++num[a[i]];
}
for(int i=1;i<=100000;++i){
ans+=(num[i]*(num[i]-1ll)*(num[i]-2ll))/6ll;
}
sort(a+1,a+n+1);
int last=1;
for(int i=1;i<=n;++i){
if(a[i]!=a[i-1]){
int x=a[i];
ull S=0;
for(int j=0;j<pr-1;++j){
int cnt=0;
while(x%pri[j]==0){
++cnt;
x/=pri[j];
}
if(cnt%2!=0){
S|=((ull)1<<j);
}
}
int y=0,z;
while(x%pri[pr-1]==0){
++y;
x/=pri[pr-1];
}
y%=2;
z=x;
vector<int> v=ma[Point(S,y,z)];
for(int j=0;j<v.size();++j){
ans+=num[a[i]]*num[v[j]]*num[(int)(sqrt((ll)a[i]*(ll)v[j])+0.5)];
}
ma[Point(S,y,z)].push_back(a[i]);
last=i;
}
}
cout<<ans<<endl;
return 0;
}
【map】【分解质因数】CDOJ1572 Espec1al Triple的更多相关文章
- light oj 1236 分解质因数
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...
- hdu 5428 The Factor 分解质因数
The Factor Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest ...
- uva10791 uva10780(分解质因数)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 1142:Smith Numbers(分解质因数)
Smith Numbers Time Limit: 1000MS Memory Limit: 10000K Total Submiss ...
- uva10780(分解质因数)
可以直接用高精度来暴力求. 也可以不用高精度: 把m分解质因数,记录每个因数和它的次数.然后计算每个因数在n的阶乘里出现了多少次,再把这个次数除以它在m中的次数,就是可能的k值.取最小的k. #inc ...
- 【CodeM初赛A轮】D 分解质因数+暴力
题目描述树链是指树里的一条路径.美团外卖的形象代言人袋鼠先生最近在研究一个特殊的最长树链问题.现在树中的每个点都有一个正整数值,他想在树中找出最长的树链,使得这条树链上所有对应点的值的最大公约数大于1 ...
- 洛谷 P1072 Hankson 的趣味题 || 打质数表的分解质因数
方法就是枚举,根据b0和b1可以大大减小枚举范围,方法类似这个http://blog.csdn.net/hehe_54321/article/details/76021615 将b0和b1都分解质因数 ...
- HDU 5428 分解质因数
The F ...
- [Codeforces 1246B] Power Products (STL+分解质因数)
[Codeforces 1246B] Power Products (STL+分解质因数) 题面 给出一个长度为\(n\)的序列\(a_i\)和常数k,求有多少个数对\((i,j)\)满足\(a_i ...
随机推荐
- 特征工程(Feature Engineering)
一.什么是特征工程? "Feature engineering is the process of transforming raw data into features that bett ...
- perl6中的q/qq/qx/qqx
q不内插 qq内插 qx不内插 qqx内插
- Open WATCOM指南 - 哦这样的孤单 你冷若冰霜
https://my.oschina.net/GIIoOS/blog/126701 WATCOM的历史可以追溯到1965年 加拿大的学生Waterloo的团队开发了叫WATFOR的Fortran编译器 ...
- 基数排序c++实现
基数排序:是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较.由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排序也不是只能使用于整数.但在 ...
- Content to Node: Self-Translation Network Embedding
paper:https://dl.acm.org/citation.cfm?id=3219988 data & code:http://dm.nankai.edu.cn/code/STNE.r ...
- 5:django 常用函数
用django写view函数的时候,我们常常用到django.shortcuts里面的很多常用函数, 这节我们来看看这些函数的具体用法吧 render render(request, template ...
- Java单线程多实例和多线程多实例
最近写了一个程序,是采用多线程往redis里面写入数据,想统计一下一共写了多少条数据,于是用了一个static的全局变量count来累加,这块代码抽象出来就是这样的: public class Mul ...
- poj 1182 (扩展并查集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 58979 Accepted: 17247 Description ...
- 【hdoj_2189】来生一起走(母函数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2189 本题的数学模型如下: 分解的问题,常用母函数求解,这里要求每个"硬币"的价值必须 ...
- .net core 2.0学习记录(四):Middleware使用以及模拟构建Middleware(RequestDelegate)管道
.net Core中没有继续沿用以前asp.net中的管道事件,而是开发了一个新的管道(Middleware): public class MiddlewareDemo { private reado ...