HDU 4279 Number(2012天津网络游戏---数论分析题)
转载请注明出处:http://blog.csdn.net/u012860063?
viewmode=contents
题目链接: pid=4279">http://acm.hdu.edu.cn/showproblem.php?pid=4279
NumberTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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.
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
Sample Output
Source
Recommend
liuyiding
|
题意:
给出一个f(x),表示不大于x的正整数里,不整除x且跟x有大于1的公约数的数的个数。
定义F(x),为不大于x的正整数里,满足f(x)的值为奇数的数的个数。题目就是求这个F(x)。
代码例如以下:(用C++提交WA了无数次,用G++一遍过)
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
//大于4。并且不是偶数的平方数的偶数是real number
//奇数的平方的奇数是real number
__int64 calc(__int64 n)//计算小于等于n的real number的个数
{
if(n<=4)
return 0;
__int64 t=sqrt(n*1.0);
__int64 ans=(n-4)/2;//大于4的偶数的个数
if(t%2==0)
return ans;
else
return ans+1;
}
int main()
{
int T;
__int64 A,B;
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d",&A,&B);
printf("%I64d\n",calc(B)-calc(A-1));
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU 4279 Number(2012天津网络游戏---数论分析题)的更多相关文章
- HDU4279(2012年天津网络赛---数论分析题)
题目:Number 题意: 给出一个f(x),表示不大于x的正整数里,不整除x且跟x有大于1的公约数的数的个数.定义F(x),为不大于x的正整数里,满足f(x)的值为奇数的数的个数.题目就是求这个F( ...
- hdu 4279"Number"(数论)
传送门 参考资料: [1]:https://www.2cto.com/kf/201308/233613.html 题意,题解在上述参考资料中已经介绍的非常详细了,接下来的内容只是记录一下我的理解: 我 ...
- HDU 4279 - Number
2012年天津赛区网赛的题目,想了好久,也没能想出来 还是小杰思路敏捷,给我讲解了一番,才让我把这个题做出来 f(x)=x-phi(x)(1——x与x互素个数)-g(x)(x的因子个数)+1 其中g( ...
- HDU 4279 Number(找规律)
Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU 4279 Number 坑爹的迷之精度
题目描述 首先定义"special number": 如果对于一个数字B,存在一个数字A(0<A<=B),并同时满足 B%A=0 和 gcd(A,B) != 1 ,那么 ...
- hdu 4279 Number(G++提交)
打表找规律: #include<stdio.h> #include<math.h> #define N 250 bool judge(int i,int j) { ;k< ...
- HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
- HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- Ubuntu下成功安装QQ2013
阳光小强最近用Win8系统感觉特别不爽,中午果断换了一个win7系统,又想着能不能搞个双系统(最近在看一些linux东西),于是就开始整起来.结果并不好,linux虽然整好了,但是硬盘全部格式化了,当 ...
- boost::any的一般使用方法
01.#include <iostream> 02.#include <list> 03.#include <boost/any.hpp> 04. ...
- Spring MVC 请求路径遇到的302问题的解决方法
302 Found 请求的资源现在临时从不同的URI响应请求.由于这样的重定向是临时的,客户端应当继续向原有地址发送以后的请求.只有在Cache-Control或Expires中进行了指定的情况下,这 ...
- Android-通过Java代码来实现属性动画
Android-通过Java代码来实现属性动画 除了能够使用定义xml文件来设置动画之外.还能够使用java代码来进行控制动画. 示比例如以下: 布局文件: <RelativeLayout xm ...
- iOS8.1 编译ffmpeg和集成第三方实现直播(监控类)
iOS8.1 编译ffmpeg和集成第三方实现直播(监控类) http://www.mamicode.com/info-detail-476094.html 一,下载并在终端中运行脚本编译ffmpeg ...
- WPF入门(三)->几何图形之不规则图形(PathGeometry)
原文:WPF入门(三)->几何图形之不规则图形(PathGeometry) 前面我们给大家介绍了LineGeometry,EllipseGeometry,CombinedGeometry等一些规 ...
- 【noip模拟】太空电梯 贪心
题目大意 人数n,电梯载重k,电梯限制人数2,给出每个人的体重v,求按照怎样的顺序排队电梯运送的次数越多. 题解 排序后,每次都先选择最小的,然后看最大的上来是否超出载重, 若超出,则这两个对答案贡献 ...
- 【最大M子段和】dp + 滚动数组
题目描述 给定 n 个数求这 n 个数划分成互不相交的 m 段的最大 m 子段和. 给出一段整数序列 A1,A2,A3,A4,...,Ax,...,An ,其中 1≤x≤n≤1,000,000, -3 ...
- Vue中this的绑定
之前写过一篇文章 ES6与React中this完全解惑 其实Vue也是相同的道理.在Vue的官方文档中提到: 不要在选项属性或回调上使用箭头函数,比如 created: () => consol ...
- Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/vm10-0-0-19
输入:service mysqld start 报错: Starting MySQL.. ERROR! The server quit without updating PID file (/usr/ ...