• 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 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;
                 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
    ",ans);
          }
          return 0;
    }
    */
    #include<cstdio>
    #include<cstring>
    #define N 100100
    
    int 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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Ubuntu16.04 中 Vscode 如何断点调试C语言程序
    PHP疑难杂症
    PHP之外观模式
    23种设计模式之适配器模式(Adapter Pattern)
    23种设计模式之原型模式(Prototype Pattern)
    23种设计模式之单例(Singleton Pattern)
    23种设计模式之抽象工厂(Abstract Factory Pattern)
    23种设计模式之工厂方法(Factory Method Pattern)
    简单工厂
    Nosql之Redis
  • 原文地址:https://www.cnblogs.com/fightfor/p/4248257.html
Copyright © 2020-2023  润新知