zoj 3629 Treasure Hunt IV(找规律)
2015-10-27 14:06
225 查看
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 fromb 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
Sample Output
View Code
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 一开始还考虑用欧拉定理算因子和什么的。。。 然后看到数据范围。。。噗。。显然不能那样做。。。 所以一开始看清楚数据范围是很重要的。 这个数据范围应该就是找规律了。。。。 结果试着找了下。。。果然有规律hhhhh 需要注意的是要分奇偶。。。 如果是偶数可能会多算。。。因为这个wa了一发。。。
/************************************************************************* > File Name: code/zoj/3629.cpp > Author: 111qqz > Email: rkz2013@126.com > Created Time: 2015年10月24日 星期六 20时07分02秒 ************************************************************************/ #include<iostream> #include<iomanip> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<stack> #include<cctype> #define yn hez111qqz #define j1 cute111qqz #define ms(a,x) memset(a,x,sizeof(a)) using namespace std; const int dx4[4]={1,0,0,-1}; const int dy4[4]={0,-1,1,0}; typedef long long LL; typedef double DB; const int inf = 0x3f3f3f3f; LL a,b; void pre() { int sum = 1; for ( int i =1; i <= 300 ; i++) { int res = 0 ; for ( int j = 1 ; j <= i ; j++) res = res + i/j; if (res%2==0) { sum++; cout<<"i:"<<i<<endl; } } printf(" sum: %d\n",sum); } LL cal( LL n) //计算0到n有多少个数满足 { if(n==0) return 1; if (n<0) return 0; LL res = 0 ; LL sn = sqrt(n); LL k = sn/2 + 1; //k为等差数列的项数,第k项为4k-3 res = (2*k-1)*k; if (sn%2==0) { res = res -(4*k-3); res = res+n-(2*k-2)*(2*k-2)+1; } // cout<<"k:"<<k<<" n:"<<n<<" res:"<<res<<endl; return res; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif //pre(); while (scanf("%lld %lld",&a,&b)!=EOF) { printf("%lld\n",cal(b)-cal(a-1)); } #ifndef ONLINE_JUDGE fclose(stdin); #endif return 0; }
View Code
相关文章推荐
- 字符串连接
- mybatis 联表查询
- debian linux 中如何查看软件包是否已经安装和如何安装、卸载软件
- Jquery插件 防刷新倒计时 “点击获取验证码后60秒内禁止重新获取
- 简历如何搞定HR
- //四舍五入//得到倒序//比较字符串//拦截时间,实现超时锁屏//判断是否越狱//配置PodFile//Storyboard中跳转操作//处理不可逆的push界面操作
- [C++] c Struct VS c++ Struct
- Android Handler leak 分析及解决办法
- linux基础入门课程---vim文本编辑器
- Android API 中文 ListView
- oracle字符函数
- LSGO软件技术团队2015~2016学年第八周(1019~1025)总结
- Python 2.7 mysql-python(MySQLdb) win7 64bit 扩展安装
- C语言中mktime函数功能及用法
- 常用的系统调用
- svm特征
- iOS中对数组的删除操作注意点
- 整理iOS9适配中出现的坑(图文)(一)
- 解决opennms NSIS安装问题 centos
- 一对多和多对一映射简介