CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题....


Program:

 

#include<iostream>
#include<stack>
#include<queue>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#define ll long long
#define oo 1000000007
#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;
}


 

 

posted @ 2013-07-25 18:09  jlins  阅读(212)  评论(0编辑  收藏  举报