CF 111B Petya and Divisors

题目描述

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}] [xiyi,xiyi+1,,xi1]中的每一个数都不能整除它。帮帮他解决这个问题吧。

输入输出格式

输入格式

第一行有一个正整数 n n n,满足 ( 1 ≤ n ≤ 10000 ) (1 \leq n\leq 10000) (1n10000)

下面有 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(1xi105,0yi1),意义如上文所述。

特别的,如果 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]

说明

样例一中前五个数的符合条件的因子如下:

  • 1 ) 1) 1) 1 , 2 , 4 1,2,4 1,2,4
  • 2 ) 2) 2) 3 3 3
  • 3 ) 3) 3) 5 5 5
  • 4 ) 4) 4) 2 , 6 2,6 2,6
  • 5 ) 5) 5) 9 , 18 9,18 9,18

题目描述

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

样例 #1

样例输入 #1

6
4 0
3 1
5 2
6 2
18 4
10000 3

样例输出 #1

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<bits/stdc++.h>

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;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

harmis_yz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值