HDU 4279 Number(找规律)
来源:互联网 发布:阿里云代理服务器 编辑:程序博客网 时间:2024/06/03 17:37
Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4288 Accepted Submission(s): 1066
Problem Description
Here are two numbers A and B (0 < A <= B). If B cannot be divisible by A, and A and B are not co-prime numbers, we define A as a special number of B.
For each x, f(x) equals to the amount of x’s special numbers.
For example, f(6)=1, because 6 only have one special number which is 4. And f(12)=3, its special numbers are 8,9,10.
When f(x) is odd, we consider x as a real number.
Now given 2 integers x and y, your job is to calculate how many real numbers are between them.
For each x, f(x) equals to the amount of x’s special numbers.
For example, f(6)=1, because 6 only have one special number which is 4. And f(12)=3, its special numbers are 8,9,10.
When f(x) is odd, we consider x as a real number.
Now given 2 integers x and y, your job is to calculate how many real numbers are between them.
Input
In the first line there is an integer T (T <= 2000), indicates the number of test cases. Then T line follows, each line contains two integers x and y (1 <= x <= y <= 2^63-1) separated by a single space.
Output
Output the total number of real numbers.
Sample Input
21 11 10
Sample Output
04HintFor the second case, the real numbers are 6,8,9,10.
Source
2012 ACM/ICPC Asia Regional Tianjin Online
题解:打个表找规律,F(x)=x/2-1+(sqrt(x)%2? 0:-1) 推荐证明:http://blog.csdn.net/acdreamers/article/details/9730423
注:sqrt()存在精度问题,精度处理不好会wa.
#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<cmath>#define ll long longusing namespace std;ll Sqrt(ll l,ll r,ll a) { ll mid=(l+r)/2; if(l>r) return r; if(a/mid>mid) return Sqrt(mid+1,r,a); else if(a/mid<mid) return Sqrt(l,mid-1,a); else return mid;}ll solve(ll r) { if(r<6)return 0; return r/2-2+(ll)Sqrt(1,r,r)%2;;}int main() { int t; cin>>t; while(t--) { ll l,r; scanf("%I64d%I64d",&l,&r); printf("%I64d\n",solve(r)-solve(l-1)); } return 0;}
0 0
- HDU 4279 Number(找规律)
- HDU 4279 Number(数学题,找规律)
- HDU 4279 Number(找规律)
- hdu 4279 Number(找规律)
- hdu 4279 Number 简单题目 找规律
- HDU 4952Number Transformation(找规律)
- HDU 4952 Number Transformation (找规律)
- hdu 1005 Number Sequence(找规律)
- HDU 1005-Number Sequence(找规律)
- HDU 1391 Number Steps(思维题目,找规律)
- HDU 1005 Number Sequence(找规律,思维)
- hdu (找规律)
- HDU 4722 Good number 找规律
- HDU 1391 Number Steps【找规律】
- HDU 1391 Number Steps(数学题+找规律)
- HDU 1005 Number Sequence(找规律)
- HDU 1005 Number Sequence 找规律
- hdu 1005 Number Sequence(找规律)
- SYN Cookie的原理和实现
- 关于android性能,内存优化
- 每日20行之4~~~两种方法java实现简易计算器 附带复杂计算器代码(优先级顺序)
- 【写一个C程序验证系统是32bit/64bit,验证系统是大端对齐还是小端对齐】
- HDU - 3836 Equivalent Sets (强连通分量+DAG)
- HDU 4279 Number(找规律)
- 【转载】设计之路:如何进行软件需求分析?
- 搭建java开发环境
- HDU - 1827 Summer Holiday(强连通分量+贪心)
- vsftpd 安装与使用
- php-实例1:简单的文章管理系统
- hadoop之家族
- ZOJ 3721 Final Exam Arrangement(贪心)
- 黑马程序员——String与StringBuffer