codeforces 567C Geometric Progression
2015-08-07 15:54
239 查看
C. Geometric Progression
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
input
output
input
output
input
output
学习前几名简短的代码:
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
using namespace std;
map<int, long long> A, B;
int main()
{
int n, k;
scanf("%d%d", &n, &k);
long long ans = 0;
for(int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
if(x % (k * k) == 0) ans += B[x / k];
if(x % k == 0) B[x] += A[x / k];
A[x]++;
}
printf("%I64d\n", ans);
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
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
学习前几名简短的代码:
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
using namespace std;
map<int, long long> A, B;
int main()
{
int n, k;
scanf("%d%d", &n, &k);
long long ans = 0;
for(int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
if(x % (k * k) == 0) ans += B[x / k];
if(x % k == 0) B[x] += A[x / k];
A[x]++;
}
printf("%I64d\n", ans);
return 0;
}
相关文章推荐
- 工作周记
- 【翻译】在Ext JS 6通用应用程序中使用既共享又特定于视图的代码
- 需要这样一个记事本-14 ReportViewer在多页报表情况下,每页都显示表格列表头
- 理解 Statement 和 PreparedStatement区别
- JNI调用遇到的问题
- ehcache memcache redis 三大缓存男高音
- 默认选中ext:GridPanel第一行数据
- HDU多赛学校9 HDU4969 Just a Joke 【数学积分】
- MFC CAD控制权问题
- net网站发布-允许更新此预编译站点 及修改发布后内容
- Php扫描目录学习记录
- 图结构练习——最小生成树
- C# 获取当前路径方法
- HDOJ 题目3065 病毒侵袭持续中(AC自动机,求字串在母串出现个数)
- hdu2955 dp
- IOS-3-Objective-C语言:单例设计模式
- Python3 列表List或元组tuple中元素分解(赋值操作)
- JSP中利用JFreechart生成图表
- ecshop 用户中心里的订单详情页显示商品缩略图
- 从“贪便宜的小市民”到“有钱的懒人”,O2O是如何彻底改变我们