转载请注明出处:http://blog.csdn.net/u012860063?

viewmode=contents

题目链接:

pid=4279">http://acm.hdu.edu.cn/showproblem.php?pid=4279

Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2936    Accepted Submission(s): 805

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
2
1 1
1 10
 
Sample Output
0
4
Hint
For the second case, the real numbers are 6,8,9,10.
 
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天津网络游戏---数论分析题)的更多相关文章

  1. HDU4279(2012年天津网络赛---数论分析题)

    题目:Number 题意: 给出一个f(x),表示不大于x的正整数里,不整除x且跟x有大于1的公约数的数的个数.定义F(x),为不大于x的正整数里,满足f(x)的值为奇数的数的个数.题目就是求这个F( ...

  2. hdu 4279"Number"(数论)

    传送门 参考资料: [1]:https://www.2cto.com/kf/201308/233613.html 题意,题解在上述参考资料中已经介绍的非常详细了,接下来的内容只是记录一下我的理解: 我 ...

  3. HDU 4279 - Number

    2012年天津赛区网赛的题目,想了好久,也没能想出来 还是小杰思路敏捷,给我讲解了一番,才让我把这个题做出来 f(x)=x-phi(x)(1——x与x互素个数)-g(x)(x的因子个数)+1 其中g( ...

  4. HDU 4279 Number(找规律)

    Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. HDU 4279 Number 坑爹的迷之精度

    题目描述 首先定义"special number": 如果对于一个数字B,存在一个数字A(0<A<=B),并同时满足 B%A=0 和 gcd(A,B) != 1 ,那么 ...

  6. hdu 4279 Number(G++提交)

    打表找规律: #include<stdio.h> #include<math.h> #define N 250 bool judge(int i,int j) { ;k< ...

  7. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  8. HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. UICollectionView使用方法补充(照片轮播墙)

    一 整体功能图和实现思路 1 完整的功能图: 2 实现功思路: 1> 流水布局(实现UICollectionView必需要的条件) 2> 自己定义cell(实现UICollectionVi ...

  2. Solving the Problem of Overfitting

    The Problem of Overfitting Cost Function Regularized Linear Regression Note: [8:43 - It is said that ...

  3. Facebook开源软件列表

    从 Facebook 的 GitHub 账户中可以看到,Facebook 已经开源的开源项目有近 300 个,领域涉及移动.前端.Web.后端.大数据.数据库.工具和硬件等.Facebook 开源项目 ...

  4. iis MP4 不能访问404

    为什么我上传了flv或MP4文件到服务器,可输入正确地址通过http协议来访问总是出现“无法找到该页”的404错误呢?这就表明mp4格式文件是服务器无法识别的,其实,这是没有在iis中将相应的MIME ...

  5. C#生成、解析xml文件以及处理报错原因

    转载自:http://blog.csdn.net/lilinoscar/article/details/21027319 简单的介绍一下生成XML文件以及解析,因为有些数据不一定放到数据库,减少链接数 ...

  6. Myeclipse - Web项目转换技巧--处理Java项目、SVN非Web项目问题

    喜欢从业的专注,七分学习的态度. 概述 对于Java调试,使用Eclipse习惯性的使用Junit调试,使用Myeclipse习惯性的将项目转成Web项目在Tomcat或Weblogic中调试,在My ...

  7. Erlang/OTP 中文手册

    http://erldoc.com/ Open Telecom Platform application array asn1rt base64 binary calendar code dbg di ...

  8. 输入框改变placeholder字体颜色

    ::-webkit-input-placeholder {  color: red;}:-moz-placeholder {  color: red;}::-moz-placeholder{color ...

  9. 《大话操作系统——扎实project实践派》(8.2)(除了指令集.完)

  10. selenium + firefox登录空间

    在网上看到的大部分都是Python版本的,于是写了个java版本的 环境: selenium-java 3.9.1 firefox 57.0 geckodriver 0.19.1 firefox与ge ...