首页 > 代码库 > Codeforces 111B【看看自己和别人在代码能力上的差距!】

Codeforces 111B【看看自己和别人在代码能力上的差距!】

我的:

#include<iostream>#include<cstring>using namespace std;int x[100001],y[100001],d[100001];int i =1;int main(){    memset(d,-1,sizeof(d));    int n;    cin>>n;    while(n--)    {        int ans = 0,m;        cin>>x[i]>>y[i];        for(int j = 1; j*j <= x[i]; j++)        {            if(x[i]%j == 0)            {                ans++;                m = j;            }        }        if(m * m == x[i])            ans = ans*2-1;        else            ans = ans*2;        if(y[i])        {            for(int j = 1; j*j <= x[i]; j++)            {                if(x[i] % j == 0 && i - d[j] <= y[i])                    ans--;                if(x[i] % (x[i]/j) == 0 && i - d[x[i]/j] <= y[i] && j != x[i]/j)                    ans--;            }            cout<<ans<<endl;        }        else if(y[i] == 0)            cout<<ans<<endl;        for(int j = 1; j*j <= x[i]; j++)        {            if(x[i]%j == 0)            {                d[j] = i;                d[x[i]/j] = i;            }        }        i++;    }}

别人的:

/*#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 100005using 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;             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;}*/#include<cstdio>#include<cstring>#define N 100100int d[N],n,x,t;int main(){    memset(d,-1,sizeof(d));    scanf("%d",&t);    for(int idx=1;idx<=t;idx++) {        scanf("%d%d",&x,&n);        int ans=0;        for(int i=1;i*i<=x;i++) {            if((x%i)==0) {                int c1=i;                int c2=x/i;                //一次可以找到两个约数,i和x/i;                if(d[c1]+n<idx) ans++;                if(c1!=c2 && d[c2]+n<idx) ans++;                d[c1]=d[c2]=idx;            }        }        printf("%d\n",ans);    }    return 0;}

 

Codeforces 111B【看看自己和别人在代码能力上的差距!】