CF818E.Card Game Again

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vova again tries to play some computer card game.

The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a__i is written on the i-th card in the deck.

After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck.

Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?

沃沃再次尝试玩某种电脑卡牌游戏。

本游戏中,构建卡组的规则很简单。沃沃会得到一个已有的、包含 nn 张卡牌的卡组,以及一个“魔法数” kk。卡组中卡牌的顺序是固定的。每张卡牌上写有一个数字;原始卡组中第 ii 张卡牌上的数字为 aia_i。

在收到该卡组和魔法数后,沃沃会从卡组顶部移除 xx(可能 x=0x = 0)张卡牌,再从底部移除 yy(可能 y=0y = 0)张卡牌;剩余部分即构成他的新卡组(注意:移除后新卡组中至少需保留一张卡牌)。因此,沃沃的新卡组实际包含原始卡组中编号为 x+1, x+2, …, n−y−1, n−yx+1,\, x+2,\, \dots,\, n-y-1,\, n-y 的卡牌。

当且仅当新卡组中所有卡牌上所写数字的乘积能被 kk 整除时,该新卡组才被视为合法的。现在,沃沃获得了一个(可能不合法的)卡组及一个数 kk,他想知道:有多少种选择 xx 和 yy 的方式,使得在从顶部移除 xx 张卡牌、从底部移除 yy 张卡牌后所得的新卡组是合法的?

输入格式

The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).

The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109) — the numbers written on the cards.

第一行包含两个整数 nn 和 kk(1≤n≤100 0001 \leq n \leq 100\,000,1≤k≤1091 \leq k \leq 10^9)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)——写在卡片上的数字。

输出格式

Print the number of ways to choose x and y so the resulting deck is valid.

输出选择 xx 和 yy 使得最终牌组有效的方案数。

输入输出样例

  • 输入#1

    3 4
    6 2 8

    输出#1

    4
  • 输入#2

    3 6
    9 1 14

    输出#2

    1

说明/提示

In the first example the possible values of x and y are:

  1. x = 0, y = 0;
  2. x = 1, y = 0;
  3. x = 2, y = 0;
  4. x = 0, y = 1.

在第一个例子中,xx 和 yy 的可能取值为:

  1. x=0, y=0x = 0,\ y = 0;
  2. x=1, y=0x = 1,\ y = 0;
  3. x=2, y=0x = 2,\ y = 0;
  4. x=0, y=1x = 0,\ y = 1。

输入解题思路,AI测评打分。不知道怎么写?

首页