• HDU 4279


    2012年天津赛区网赛的题目,想了好久,也没能想出来

    还是小杰思路敏捷,给我讲解了一番,才让我把这个题做出来

    f(x)=x-phi(x)(1——x与x互素个数)-g(x)(x的因子个数)+1

    其中g(x)为multiply(q(i)+1),x=multiply(p(i)^q(i))(p(i)为所有素因子)

    打表可得,phi(x)只有x=2时为奇数,其余全为偶数,而f(2)=0,可以不予考虑

    所以,f(x)为odd的时候,x和g(x)模2同余

    1、当x为odd时,q(i)+1全为odd,即q(i)必为even,所以x必为odd的平方数

    2、当x为even时,q(i)+1全为even,即q(i)必为odd,所以x即为所有even减去even的平方数

    最终可得公式 F(0——x)=x/2-2+(x==odd的平方数)

    #include <stdio.h>
    #include <math.h>
    #define LL long long
    
    LL solve(LL x)
    {
        if(x<=5)return 0;
        LL ou=x/2-2;
        LL k=sqrt(x);
        LL ans=(k-3+2)/2+ou-(k-4+2)/2;
        return ans;
    }
    
    int main()
    {
        int T;
        LL x,y;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%I64d%I64d",&x,&y);
            printf("%I64d
    ",solve(y)-solve(x-1));
        }
    
        return 0;
    }
    


  • 相关阅读:
    北方联动科技论坛上的回答
    Fire Net
    The shortest problem(hdu,多校
    Air Raid
    过山车
    Courses
    Network
    Common Subsequence
    The mook jong
    Distribution money
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3235426.html
Copyright © 2020-2023  润新知