Codeforces Round #596 (Div. 2)D. Power Products

Codeforces Round #596 (Div. 2)D. Power Products

http://codeforces.com/contest/1247/problem/D

题意:给出一串序列和k,找到满足 1 ≤ i < j ≤ n 1\leq i<j\leq n 1i<jn的对 ( i , j ) (i,j) i,j,满足:存在一个 x x x,使得, a i a j = x k a_ia_j=x^k aiaj=xk

做法:两个数相乘能表示成 x k x^k xk,说明 a i a j = p 1 k 1 p 2 k 2 … … p m k m a_ia_j=p_1^{k_1}p_2^{k_2}……p_m^{k_m} aiaj=p1k1p2k2pmkm中, k i k_i ki均为 k k k的倍数,将每一个数分解质因数,得到质因子和对应的幂次(模m后),并找到对应的能和它结合,满足条件的 a i a_i ai的个数

用map记录下vector的数量是真的骚……

AC代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<queue>
#include<map>
#define ll long long
#define pb push_back
#define rep(x,a,b) for (int x=a;x<=b;x++)
#define repp(x,a,b) for (int x=a;x<b;x++)
#define W(x) printf("%d\n",x)
#define WW(x) printf("%lld\n",x)
#define pi 3.14159265358979323846
#define mem(a,x) memset(a,x,sizeof a)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
using namespace std;
const int maxn=2e6+7;
const int INF=1e9;
const ll INFF=1e18;
typedef pair<int,int > P;
map<vector<P > ,int > M;
int main()
{
    int n,k,x;
    ll ans=0;
    cin>>n>>k;
    rep(i,1,n)
    {
        vector<P> v1,v2;
        cin>>x;
        for (int j=2;j*j<=x;j++)
        {
            if (x%j==0)
            {
                int cnt=0;
                while(x%j==0)
                {
                    x/=j;
                    cnt++;
                }
                if (cnt%k!=0)v1.pb(make_pair(j,cnt%k));
            }
        }
        if (x>1) v1.pb(make_pair(x,1));
        for (int j=0;j<v1.size();j++)
            v2.pb(make_pair(v1[j].first,k-v1[j].second));
        ans+=M[v2];//v2状态为与v1状态互补,可以结合
        M[v1]++;//v1状态数量+1
    }
    cout<<ans<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值