Geometric Progression

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.

He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.

A subsequence of length three is a combination of three such indexes i1, i2, i3, that 1 ≤ i1 < i2 < i3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.

A geometric progression with common ratio k is a sequence of numbers of the form b·k0, b·k1, ..., b·kr - 1.

Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.

Input

The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number.

The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — elements of the sequence.

Output

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.

Sample Input

Input
5 2
1 1 2 2 4
Output
4
Input
3 1
1 1 1
Output
1
Input
10 3
1 2 6 2 3 6 9 18 3 9
Output
6

Hint

In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.

 #include <stdio.h>
#include <string.h>
#include <map>
#include <algorithm>
using namespace std; map <long long,long long> a;
map <long long,long long> b;
long long y[];
int main()
{
long long n,k,o;
long long i,j,x,m;
long long s;
while(scanf("%I64d %I64d",&n,&k)!=EOF)
{
s=,o=,m=;
a.clear();
b.clear();
if(k==)
{
for(i=;i<=n;i++)
{
scanf("%I64d",&x);
a[x]++;
if(a[x]==)
{
m++;
y[m]=x;
}
}
//prlong longf("*%d %d\n",a[y[1]],m);
for(i=;i<=m;i++)
{
s=s+(a[y[i]]*(a[y[i]]-)/)*(a[y[i]]-)/;
}
}
else
{
for(i=;i<=n;i++)
{
scanf("%I64d",&x);
if(x==)
o++;
a[x]++;
if(x%k== && x/k!=)
{
s=s+b[x/k];
b[x]=a[x/k]+b[x];
}
}
s=s+o*(o-)/*(o-)/;
}
printf("%I64d\n",s);
}
return ;
}

CodeForces 567C Geometric Progression的更多相关文章

  1. CodeForces 567C. Geometric Progression(map 数学啊)

    题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...

  2. Codeforces 567C - Geometric Progression - [map维护]

    题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...

  3. Codeforces 567C Geometric Progression(思路)

    题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...

  4. CodeForces 567C Geometric Progression 类似dp的递推统计方案数

    input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...

  5. CF 567C Geometric Progression

    题目大意:输入两个整数 n 和 k ,接下来输入n个整数组成的序列.求该序列中三个数 满足条件的子串个数(要求字串由三个整数a,b,c组成,其中 c = k * b = k * k * a). 思路: ...

  6. Codeforces 567C:Geometric Progression(DP)

    time limit per test : 1 second memory limit per test : 256 megabytes input : standard input output : ...

  7. Codeforces Round #Pi (Div. 2) C. Geometric Progression map

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  9. Codeforces Round #Pi (Div. 2) C. Geometric Progression

    C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...

随机推荐

  1. 夺命雷公狗ThinkPHP项目之----企业网站23之网站前台二级分类的跳转(URL跳转到列表页或产品页)

    我们现在开始做实现我们的二级菜单如何跳转到指定的列表页或者产品也呢?? 我们分享下数据库情况: 我们的数据库里提前给我们预留了一个cate_type的字段,那么我们可以让这个字段进行判断,从而遍历出指 ...

  2. GLSL第一个程序

    拿出来直接运行即可,可以直接理解什么是GLSL,之所以贴出来是因为很多文章写得乱七八糟,一面解释,一面贴代码,有必要吗??很多GLSL电子书都有很详细的解释的. 我的OpenGL框架代码可能和你的框架 ...

  3. android 学习随笔七(网络:图片及文本传输及线程关系 )

    主线程.子线程.UI的关系 简单的HTTP请求 -------------------------------------------------------- public class MainAc ...

  4. 网卡ifcfg-eth0配置

    ifcfg-ethx网卡配置 文件路径 [root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0     ...

  5. ubuntu下配置tomcat

    配置tomcat 1.解压 tar -zxvf apache-tomcat-7.0.53.tar.gz 2.修改/bin/catalina.sh cygwin=falsedarwin=falseos4 ...

  6. (转)java线程安全问题之静态变量、实例变量、局部变量

    java多线程编程中,存在很多线程安全问题,至于什么是线程安全呢,给出一个通俗易懂的概念还是蛮难的,如同<java并发编程实践>中所说: 写道 给线程安全下定义比较困难.存在很多种定义,如 ...

  7. html5 canvas 笔记三(绘制文本和图片)

    绘制文本 fillText(text, x, y [, maxWidth])   在指定的(x,y)位置填充指定的文本,绘制的最大宽度是可选的. strokeText(text, x, y [, ma ...

  8. JavaEE基础(二)

    1.Java语言基础(常量的概述和使用) A:什么是常量 在程序执行的过程中其值不可以发生改变 B:Java中常量的分类 字面值常量 自定义常量(面向对象部分讲) C:字面值常量的分类 字符串常量 用 ...

  9. Meisell-Lehmer算法(统计较大数据里的素数)

    http://acm.hdu.edu.cn/showproblem.php?pid=5901 1e11的数据量,这道题用这个算法花了202ms. #include<bits/stdc++.h&g ...

  10. Serializable接口使用纪实

    这两天依领导要求使用sonar工具测试了一下项目代码,其中有一个问题是 而这个类的结构大概是这样的: public class Demo<T> implements Serializabl ...