zoukankan      html  css  js  c++  java
  • Codeforces Round #596 D. Power Products 暴力 stl

    D. Power Products

    time limit per test

    2 seconds

    memory limit per test

    512 megabytes

    input

    standard input

    output

    standard output

    You are given nn positive integers a1,…,ana1,…,an, and an integer k≥2k≥2. Count the number of pairs i,ji,j such that 1≤i<j≤n1≤i<j≤n, and there exists an integer xx such that ai⋅aj=xkai⋅aj=xk.

    Input

    The first line contains two integers nn and kk (2≤n≤1052≤n≤105, 2≤k≤1002≤k≤100).

    The second line contains nn integers a1,…,ana1,…,an (1≤ai≤1051≤ai≤105).

    Output

    Print a single integer — the number of suitable pairs.

    Example

    input

    Copy

    6 3
    1 3 9 8 24 1
    

    output

    Copy

    5
    

    Note

    In the sample case, the suitable pairs are:

    • a1⋅a4=8=23a1⋅a4=8=23;
    • a1⋅a6=1=13a1⋅a6=1=13;
    • a2⋅a3=27=33a2⋅a3=27=33;
    • a3⋅a5=216=63a3⋅a5=216=63;
    • a4⋅a6=8=23a4⋅a6=8=23.

    我写了很暴力的方法

    分解质因子,然后计算出每个数要构成k次方数,所需的剩余因子个数

    然后映射一个数量 每次查询map

    用一个map<vector<pair<int,int> >,int>  来对应每个数所需要的因子和个数即可

    #include<bits/stdc++.h>
    using namespace std;
    map<vector<pair<int,int> >, int>mp;
    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        long long ans=0;
        for(int i=1;i<=n;i++)
        {
            vector<pair<int,int> >ve;
            ve.clear();
            int tmp,temp;
            scanf("%d",&tmp);
            ve.push_back(make_pair(1,1));
            temp=sqrt(tmp);
            for(int j=2;j<=temp;j++)
            {
                int num=0;
                while(tmp%j==0)
                {
                    tmp/=j;
                    num++;
                }
                num%=k;
                if(num!=0)
                {
                    ve.push_back(make_pair(j,num));
                    //cout<<j<<" "<<num<<endl;
                }
            }
            if(tmp!=1)
            {
                ve.push_back(make_pair(tmp,1));
                //cout<<tmp<<" "<<1<<endl;
            }
            ans+=mp[ve];
            for(int j=1;j<ve.size();j++)
            {
                ve[j].second=k-ve[j].second;
            }
            //cout<<ve[1].second<<endl;
            mp[ve]++;
            //cout<<ans<<endl;
        }
        printf("%I64d
    ",ans);
  • 相关阅读:
    shopping car 1.0
    文件分类
    求1-100的所有数的和
    输出 1-100 内的所有奇数和
    求1-2+3-4+5 ... 99的所有数的和
    关闭提示的下拉框
    h5页面乱码-设置编码
    常用的css
    渲染后新元素没有绑定事件
    爬虫日记-关于一些动态爬取
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852200.html
Copyright © 2011-2022 走看看