zoukankan      html  css  js  c++  java
  • hdu 5750

    AC:

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define maxn 100005
    using namespace std;
    bool check[maxn];
    int pr[maxn / 5], mn[maxn];
    int tt[maxn];
    int tot;
    int T;
    void euler() {
        memset(check,0,sizeof(check));
        tot=0;
        //x=1时的函数值 
        for(int i=2;i<maxn;i++) {
            if(!check[i]) {
                pr[++tot]=i;
                mn[i] = i;
                tt[i] = 1;
                //质数函数值 
            }
            for(int j=1;j<=tot;j++) {
                if(i*pr[j]>maxn) break;
                check[i*pr[j]]=1;
                
                mn[i*pr[j]] = pr[j];
                    
                if(i%pr[j]==0) {
                    break;
                } 
            }
        } 
    }
    int main()
    {
        euler();
        tt[0] = 0;
        for (int i = 1; i < maxn; ++ i) tt[i] += tt[i - 1];            //预处理出小于i的素数的个数 
        scanf("%d", &T);
        while (T --)
        {
            int n, d, ans;
            scanf("%d%d", &n, &d); n --;
            if (d >= maxn)
            {
                ans = n / d;
                for (int i = 1; pr[i] < ans; ++ i)
                    if (d % pr[i] == 0) {ans = pr[i]; break;}
                printf("%d
    ", tt[ans]);
            }
            else printf("%d
    ", tt[min(n / d, mn[d])]);
        }
    }

    几乎一模一样但WA:

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define maxn 100005
    using namespace std;
    bool isprime[maxn];
    int pr[maxn / 5], mn[maxn];
    int tt[maxn];
    int tot;
    int T;
    void euler() {
        memset(isprime,1,sizeof(isprime));
        tot=0;
        //x=1时的函数值 
        for(int i=2;i<maxn;i++) {
            if(isprime[i]) {
                pr[++tot]=i;
                mn[i] = i;
                tt[i] = 1;
                //质数函数值 
            }
            for(int j=1;j<=tot;j++) {
                if(i*pr[j]>maxn) break;
                isprime[i*pr[j]]=0;
                
                mn[i*pr[j]] = pr[j];
                    
                if(i%pr[j]==0) {
                    break;
                } 
            }
        } 
    }
    int main()
    {
        euler();
        tt[0] = 0;
        for (int i = 1; i < maxn; ++ i) tt[i] += tt[i - 1];            //预处理出小于i的素数的个数 
        scanf("%d", &T);
        while (T --)
        {
            int n, d, ans;
            scanf("%d%d", &n, &d); n --;
            if (d >= maxn)
            {
                ans = n / d;
                for (int i = 1; pr[i] < ans; ++ i)
                    if (d % pr[i] == 0) {ans = pr[i]; break;}
                printf("%d
    ", tt[ans]);
            }
            else printf("%d
    ", tt[min(n / d, mn[d])]);
        }
    }
  • 相关阅读:
    SQL Server 2005: About login password hashes
    record drop database in sql log
    一些锁的示例
    find the physical location for specified data row
    运行sp_xp_cmdshell_proxy_account 出现的错误
    删除用户出现的错误
    conversion to dalvik format failed with error 1
    文章标题 标签提取
    in order to continue installation,please close the following application;
    提示找不到 C:\Program Files\VMware\dndlogs\dndlog.conf
  • 原文地址:https://www.cnblogs.com/zhangjialu2015/p/5700331.html
Copyright © 2011-2022 走看看