➤ Problem Link : 567C. Geometric Progression
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
struct st{
ll onel,twol,threel;
};
typedef struct st S;
map<int,S> mp;
int main()
{
int n,k;
cin>>n>>k;
ll arr[n+1];
arr[0]=-1;
mp[0].onel=0;
mp[1].twol=0;
mp[2].threel=0;
for(int i=1;i<=n;i++)
{
cin>>arr[i];
mp[arr[i]].onel=0;
mp[arr[i]].twol=0;
mp[arr[i]].threel=0;
}
ll ans=0;
for(int i=1;i<=n;i++)
{
if(arr[i]%k==0)
{
ans+=mp[arr[i]/k].twol;
mp[arr[i]].twol+=mp[arr[i]/k].onel;
}
mp[arr[i]].onel++;
}
cout<<ans;
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
