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) ...
随机推荐
- 【t099】最接近神的人
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古 ...
- 如何在hadoop中控制map的个数 分类: A1_HADOOP 2015-03-13 20:53 86人阅读 评论(0) 收藏
hadooop提供了一个设置map个数的参数mapred.map.tasks,我们可以通过这个参数来控制map的个数.但是通过这种方式设置map的个数,并不是每次都有效的.原因是mapred.map. ...
- GAN(Generative Adversarial Networks) 初步
1. Generator vs. Discriminator 首先需要指出的是生成式模型(generative models)和判别式模型(discriminative models)的区别: dis ...
- 最小生成树(MST)求解旅行商问题
从当前位置开始(也可以不指定起始位置),访问完所有未访问的端点后返回起始点的最短路径就是连接所有端点的生成树.最小生成树需保证: 每条边最多只能被选 1 次: 抹掉所有未被选择的边时,图形不能分为上下 ...
- matplotlib学习之散点图与条形图
# coding:utf-8 from matplotlib import pyplot as plt import numpy as np plt.style.use('ggplot') x = n ...
- 简要分析武汉一起好P2P平台的核心功能
写作背景 加入武汉一起好,正式工作40天了,对公司的核心业务有了更多的了解,想梳理下自己对于P2P平台的认识. 武汉一起好,自己运营的yiqihao.com,是用PHP实现的,同时也帮助若干P2P平台 ...
- 广播(broadcast)、电视与电视网络
1. 闭路电视与电视 Closed Circuit Television (CCTV) 一种图像通信系统.其信号从源点只传给预先安排好的与源点相通的特定电视机.广泛用于大量不同类型的监视工作.教育.电 ...
- 【t010】最近距离
Time Limit: 1 second Memory Limit: 32 MB [问题描述] 聚类方法要求将空间中的点集,按照一点的方式进行归类,要求每一类中的点集相互之间的距离足够的"近 ...
- [SCSS] Reuse Styles with the SCSS @extend Directive
We can write reusable styles with the SCSS @extend or @mixin directives. Which one is better? It dep ...
- css3-1 css3游戏介绍、css3样式和优先级
css3-1 css3游戏介绍.css3样式和优先级 一.总结 一句话总结:我们写外部css表的时候可以用class,那样使用的人用id修改的话优先级就比我们高,达到目的. 1.html嵌套css样式 ...