zoukankan      html  css  js  c++  java
  • zoj 3629 Treasure Hunt IV 打表找规律

    H - Treasure Hunt IV

    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

    Description

      Alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled a from b in front of her.
      Alice was very excited but unfortunately not all of the treasures are real, some are fake.
      Now we know a treasure labled n is real if and only if [n/1] + [n/2] + ... + [n/k] + ... is even.
      Now given 2 integers a and b, your job is to calculate how many real treasures are there.

    Input

      The input contains multiple cases, each case contains two integers a and b (0 <= a <= b <= 263-1) seperated by a single space. Proceed to the end of file.

    Output

      Output the total number of real treasure.

    Sample Input

    0 2
    0 10
    

    Sample Output

    1
    6

    题意:给你一个Long long范围的区间,然后问里面有多少个数,满足n/1+n/2+n/k……加起来等于一个偶数
    题解:首先打表,然后我们发现这种数是扎堆存在的,[0,1),[4,9),[16,25),……
    然后我们就这样子找规律,然后一个等差数列求和就好啦!

    LL solve(LL n)
    {
        LL m = (LL)sqrt(n*1.0);
        LL sum=0;
        if(m%2==0) sum = n-m*m;
        if(m%2==1) m++;
        LL j=m/2;
        sum=sum-j+2*j*j;
       // sum=sum+2*j*j-j;
        return sum;
    }
    int main()
    {
        LL n,m;
        while(scanf("%llu%llu",&n,&m)>0)
        {
            n++,m++;
            LL ans=solve(n-1);
            LL cur =solve(m);
            printf("%llu
    ",cur-ans);
        }
        return 0;
    }
  • 相关阅读:
    ActiveX控件开发总结(续)
    Guru of the Week 条款04: 类的构造技巧
    tk
    C++中一个空类的大小为什么是1?
    虚继承
    计算机单位
    Guru of the week:#18 迭代指针.
    kingofark关于学习C++和编程的50个观点
    Guru of the Week 条款06:正确使用const
    Guru of the Week 条款07:编译期的依赖性
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4320225.html
Copyright © 2011-2022 走看看