CodeForces 111B Petya and Divisors

B. Petya and Divisors
time limit per test
5 seconds
memory limit per test
256 megabytes

Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:

You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.

Input

The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi(1 ≤ xi ≤ 1050 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1).

If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.

Output

For each query print the answer on a single line: the number of positive integers k such that 

Sample test(s)
input
6
4 0
3 1
5 2
6 2
18 4
10000 3
output
3
1
1
2
2
22
Note

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 <iostream>  
#include <cstdio>  
#include <vector>  
#include <math.h>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;  

int v[100000+10];

void find(int x,int y,int num){
	int i,j,k,t,m,n;
	int cnt=0;

	for(i=1;i*i<=x;i++){
		if(x%i==0){
			j = x/i;
			if(v[i]<num-y)
				cnt++;
			if(i!=j && (v[j]<num-y))
				cnt++;
			v[i] = v[j] =num;
		}
	}
	printf("%d\n",cnt);
}

int main()
{
	int i,j,k,t,m,n;
	cin>>n;
	for(i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		find(x,y,i);
	}
	
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值