首页 > 其他分享 >Codeforces Round #596 D

Codeforces Round #596 D

时间:2023-02-03 10:05:20浏览次数:42  
标签:tmp Power 596 ll Codeforces mp INF include Round

Codeforces Round #596 D_#include

找到a[i]*a[j]=x^k符合这个式子的有多少种组合。

分解质因子来做就行了

AC代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
#include<map>
using namespace std;
typedef long long ll;
typedef double ld;
const int INF = 1e5+9;
map<ll,ll> mp;

ll Power(ll x,ll n)
{
    ll ret = 1;
    for(ll i=1; i<=n; i++)
        ret *= x;
    return ret;
}

int main()
{
    ll n,k,ans=0;
    cin>>n>>k;
    for(ll i=1; i<=n; i++)
    {
        ll tmp;
        cin>>tmp;
        ll x=1,y=1;
        for(ll j=2; j*j<=tmp; j++)
        {
            int cnt=0;
            while((tmp%j)==0)
            {
                tmp/=j;
                cnt++;
            }
            cnt%=k;
            if(cnt==0)
                continue;
            x*=Power(j,cnt);
            y*=Power(j,k-cnt);
            if(x>INF*INF)
                x=0;
            if(y>INF*INF)
                y=0;
        }
        x*=Power(tmp,1);
        y*=Power(tmp,k-1);
        if(x>INF*INF)
            x=0;
        if(y>INF*INF)
            y=0;
        if(y)
            ans+=mp[y];
        if(x)
            mp[x]++;
    }
    cout<<ans<<endl;
    return 0;
}

 

标签:tmp,Power,596,ll,Codeforces,mp,INF,include,Round
From: https://blog.51cto.com/u_15952369/6034926

相关文章

  • Codeforces-343D Water Tree(树链剖分)
    Description:MadscientistMikehasconstructedarootedtree,whichconsistsof n vertices.Eachvertexisareservoirwhichcanbeeitheremptyorfilledw......
  • Codeforces Round #596 B2. TV Subscriptions
    题意就是让你在N个数中找到D个连续的数,使这D个数中不同的数最小。hard数据较大,优化到nlogn才能过。具体怎么优化看代码吧AC代码:#include<cstdio>#include<cstring>......
  • Codeforces Round #596 C. p-binary
    给定N和p,让你找到满足2^x+p最少有多少不同的项。就把N转成二进制然后枚举P的个数就是答案,昨天特判没写好,今天早上起来发现被卡掉了。rank又出1000了。AC代码:#include<......
  • Educational Codeforces Round 75 D. Salary Changing(二分)
    题意就是:给n个人发工资,总钱数为s。每个人有一个工资范围。要求一个发工资方案,使得工资中位数最大,求这个中位数。考虑到中位数最大,于是我们可以二分。但是每个人的工资......
  • Educational Codeforces Round 75 C Minimize The Integer
    这道题的意思就是给出一个由数字组成的字符串,相邻的数字可以互换位置,但是如果相邻的为同奇同偶这样就不能交换。让我们求交换任意次数可以产生的最小数。这条限制就是说......
  • codeforces 595 C2. Good Numbers (hard version)
    给出Q组查询,每组给出一个N找到一个>=n的m,m可以分解成不同的3的幂次相加。可以看题意解释,就是转化为3^0,3^1,...,3^m,每个只能出现最多一次,但是可以不同组合,输出符合条件最......
  • codeforces 595 B2 Books Exchange (hard version)
    这道题的意思就是有n本书,每本书都有自己的编号,每次可以移动一本书,把这个本书移动到当前编号对应的位置,求移动几次可以使得编号和位置对应起来。比如样例32312第一......
  • Codeforces Round #848 (Div. 2)(持续更新)
    Preface这场打的可以说发挥了水平但没有完全发挥的说ABC都是一眼一遍过,结果D是我最怕的期望题,大概推了个DP的式子但感觉成环了初始条件又不够(flag)就弃了本来当时看E只有......
  • Codeforces Round #845 (Div. 2) and ByteRace 2023(A,B,C)
    CodeforcesRound#845(Div.2)andByteRace2023(A,B,C)AA这个题目大意是有n个数,我们需要让ai和ai+1的奇偶性不一样我们可以让相邻的两个数变成一个数,那个数就是这两个......
  • 2.2 vp Codeforces Round #848 (Div. 2)
    A-FlipFlopSum题意给出长度为n的序列a,a中只包括1和-1,你必须操作一次,让相邻两个元素由1变-1或由-1变1,问操作后数组总和最大多少思路暴力即可voidsolve(){ intn......