Time Limit:5000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u:
Description
描述:
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 ≤ 105, 0 ≤ 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 thatSample Input
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Hint
提示
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
共有t組數據,每組有兩個數據,x,y;求x中沒在前y組數據中出現的因子個數,
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#define ll long long
#define MAXN 100005
using namespace std;
int last[MAXN];
int main()
{
int T,t;
scanf("%d",&T);
memset(last,-1,sizeof(last)); //記錄該因子最晚在哪組出現過
for (t=1;t<=T;t++)
{
int x,y,ans,i,p;
ans=0;
scanf("%d%d",&x,&y);
for (i=1;i*i<=x;i++)
if (x%i==0)
{
if (t-last[i]>y) ans++;
if (x-i*i && t-last[x/i]>y) ans++;
last[i]=last[x/i]=t;
}
printf("%d\n",ans);
}
return 0;
}