zoj 3629 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=;
if(m%==) sum = n-m*m;
if(m%==) m++;
LL j=m/;
sum=sum-j+*j*j;
// sum=sum+2*j*j-j;
return sum;
}
int main()
{
LL n,m;
while(scanf("%llu%llu",&n,&m)>)
{
n++,m++;
LL ans=solve(n-);
LL cur =solve(m);
printf("%llu\n",cur-ans);
}
return ;
}
zoj 3629 Treasure Hunt IV 打表找规律的更多相关文章
- ZOJ3629 Treasure Hunt IV(找规律,推公式)
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- zoj Treasure Hunt IV
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- ZOJ3629 Treasure Hunt IV(找到规律,按公式)
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
- HDU2149-Good Luck in CET-4 Everybody!(博弈,打表找规律)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- 最短路径—Floyd算法
Floyd算法 所有顶点对之间的最短路径问题是:对于给定的有向网络G=(V,E),要对G中任意两个顶点v,w(v不等于w),找出v到w的最短路径.当然我们可以n次执行DIJKSTRA算法,用FLOYD ...
- 移动端测试===PROC系列之---/proc/pid/stat 如何准确取cpu的值【转】
/proc/ /stat 包含了所有CPU活跃的信息,该文件中的所有值都是从系统启动开始累计到当前时刻. [root@localhost ~]# cat /proc/6873/stat 68 ...
- OpenStack Benchmark - Rally
作为以基于OpenStack的云平台的基准测试工具 -- Rally, 其功能不仅是测试云的性能&&稳定性, 还可以安装OpenStack,以及以良好的表现形式(web 页面)展现测试 ...
- day06作业
一.方法 1.方法是完成特定功能的代码块. 修饰符 返回值类型 方法类型(参数类型 参数名1,参数类型 参数名2,...){ 方法体语句: return返回值: } 修饰符:目前就用publi ...
- ASP .NET Core 2.0 MVC 发布到 IIS 上以后 无法下载apk等格式的文件
ASP .NET Core MVC 发布到 IIS 上以后 无法下载apk等格式的文件 使用.NET Core MVC创建了一个站点,其他文件可以下载,但是后来又需求,就把手机端的apk合适的文件上 ...
- java基础18 String字符串和Object类(以及“equals” 和 “==”的解析)
一.String字符串 问:笔试题:new String("abc")创建了几个对象?答:两个对象,一个对象是 位于堆内存,一个对象位于字符串常量池 class Demo17 { ...
- Java--Jackson转换Date,Timestamp 到格式化字符串
package com.diandaxia.test; import java.sql.Timestamp; import java.util.Date; /** * Created by del-b ...
- 一张图来帮你理解 SOA
SOA 曾经一度是技术领域中最难以理解的一个概念.SOA 似乎让很多人感到困惑 - 一般来讲这是由于人们认为它拥有几乎神奇的力量.事实上 SOA 只是一个很简单的概念:SOA 由诸如 C++ 和 Ja ...
- 面试题:输入两个整数 n 和 m,从数列1,2,3…….n 中 随意取几个数, 使其和等于 m
问题: 2010年中兴面试题 编程求解: 输入两个整数 n 和 m,从数列1,2,3…….n 中 随意取几个数, 使其和等于 m ,要求将其中所有的可能组合列出来. 思路: 类似这种组合问题一般都是使 ...
- C/C++经典面试题
1.指向数组的指针 和 指向数组首元素的指针 2018-03-07 昨天在牛客上看到这么一道C语言面试题,挺经典的,特来分享给大家. 程序如下,问输出结果 #include <stdio.h&g ...