A11011 | Card Game Again
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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?
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?
输入格式
The first line contains two integers $n$ and $k$ ( $1<=n<=100000$ , $1<=k<=10^{9}$ ).
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — the numbers written on the cards.
The second line contains $n$ integers $a_{1}$ , $a_{2}$ , ..., $a_{n}$ ( $1<=a_{i}<=10^{9}$ ) — the numbers written on the cards.
输出格式
Print the number of ways to choose $x$ and $y$ so the resulting deck is valid.
输入输出样例
输入 #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$ .
1. $x=0,y=0$ ;
2. $x=1,y=0$ ;
3. $x=2,y=0$ ;
4. $x=0,y=1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted