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;
    }
  • 相关阅读:
    深度学习 框架比较
    深度学习 Fine-tune 技巧总结
    基于Spark环境对比Python和Scala语言利弊
    【Python系列】HDF5文件介绍
    【Git】CentOS7 通过源码安装Git
    【Git】Git工具常用命令
    登录自动跳转
    offset,scroll,client系列
    谷歌浏览器input中的text 和 button 水平对齐的问题
    git 的基本使用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4320225.html
Copyright © 2011-2022 走看看