http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23019
给你n 对X,Y
要求出 X的所有因子 中 ,不能整除 【当前X】以前的y个Xi的 个数
例如:
给
n=1e5, x,y<=1e5
3 1
5 2
6 2
.
对于第三组,,6的因子有 1 2 3 6 ,其中 因子 3 1 会被前Y个数 (3和5) 整除,所以他们不合法,所以答案的个数为 2 (2,6符合要求)
反了个傻逼错误,以为求因子 的复杂度是O(n),后来才发现原来是 sqrt(n)
直接暴力 n*sqrt(n)完全没问题
用一个数组标记一个数,作为因子 最后出现在 第vis【i】个数
开始vis数组初始化为-1;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include<queue>
using namespace std;
int vis[100005];
int main()
{
int i,j;
int n;
int x,y;
cin>>n;
memset(vis,-1,sizeof(vis));
for (i=1;i<=n;i++)
{
int ans=0;
scanf("%d%d",&x,&y);
int len=sqrt((double)x);
for (j=1;j<=len;j++)
{
if (x%j) continue;
if (i-y>vis[j]) ans++;
vis[j]=i;
if (j*j==x) continue;
if (i-y>vis[x/j]) ans++;
vis[x/j]=i;
}
printf("%d\n",ans);
}
return 0;
}
3 15 26 2