Petya喜欢寻找数字的因子。有一天他看到了这样的一条题目 : : :
有 n n n个形如 [ x , y ] [x,y] [x,y]的二元组,对于每一个二元组,Petya希望找到有多少个 x i x_i xi的因子,使得在 [ x i − y i , x i − y i + 1 , ⋯ , x i − 1 ] [x_{i-y_i},x_{i-y_i+1},\cdots,x_{i-1}] [xi−yi,xi−yi+1,⋯,xi−1]中的每一个数都不能整除它。帮帮他解决这个问题吧。
第一行有一个正整数 n n n,满足 ( 1 ≤ n ≤ 10000 ) (1 \leq n\leq 10000) (1≤n≤10000)
下面有 n n n行,每行 2 2 2个非负整数 x i x_i xi与 y i ( 1 ≤ x i ≤ 1 0 5 , 0 ≤ y ≤ i − 1 ) y_i(1 \leq x_i \leq 10^5 ,0 \leq y \leq i-1) yi(1≤xi≤105,0≤y≤i−1),意义如上文所述。
特别的,如果 y i = 0 y_i=0 yi=0,结果就是 x i x_i xi因子的个数。
共 n n n行,每行 1 1 1个数,表示有多少个 k k k,满足$[x_i $ m o d mod mod k = 0 k=0 k=0并且$(\forall j:i-y_i \leq j < i) $ m o d mod mod k ≠ 0 ] k \not = 0] k=0]
样例一中前五个数的符合条件的因子如下:
Little Petya loves looking for numbers’ divisors. One day Petya came across the following problem:
You are given $ n $ queries in the form " $ x_{i} $ $ y_{i} $ ". For each query Petya should count how many divisors of number $ x_{i} $ divide none of the numbers $ x_{i-yi},x_{i-yi}+1,…,x_{i-1} $ . Help him.
The first line contains an integer $ n $ ( $ 1<=n<=10^{5} $ ). Each of the following $ n $ lines contain two space-separated integers $ x_{i} $ and $ y_{i} $ ( $ 1<=x_{i}<=10^{5} $ , $ 0<=y_{i}<=i-1 $ , where $ i $ is the query’s ordinal number; the numeration starts with $ 1 $ ).
If $ y_{i}=0 $ for the query, then the answer to the query will be the number of divisors of the number $ x_{i} $ . In this case you do not need to take the previous numbers $ x $ into consideration.
For each query print the answer on a single line: the number of positive integers $ k $ such that
6
4 0
3 1
5 2
6 2
18 4
10000 3
3
1
1
2
2
22
Let’s write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
#include
using namespace std;
int l[1000000];
int T;
int main()
{
cin>>T;
memset(l,-1,sizeof(l));
for(int k=1;k<=T;k++)
{
int x,y;
int ans=0;
cin>>x>>y;
for(int i=1;i<=x/i;i++)
{
if(x%i==0)
{
if(k-l[i]>y)
{
ans++;
}
if(x-i*i!=0&&k-l[x/i]>y)
{
ans++;
}
l[i]=l[x/i]=k;
}
}
cout<<ans<<endl;
}
return 0;
}