HDU 4279 Number

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

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4279

HDU集训队选拔赛地点:3教3楼机房,时间:5月10日(周六)12:00开始,请相互转告,谢谢~

百度之星编程大赛——您报名了吗?

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

2012 ACM/ICPC
Asia Regional Tianjin Online

Recommend

liuyiding

代码如下:(用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

时间: 2025-01-01 09:12:31

HDU 4279 Number的相关文章

HDU 4279 Number 规律题

题意: 定义函数F(x) : 区间[1,x]上的y是满足:GCD(x,y)>1 && x%y>0的 y的个数. 问:对于任意区间[l,r] 上的F(l···r) 有几个函数值是奇数的. 打表找规律. 打的是[1,x]区间的结果 把所有结果不相同的值打出来(因为结果是递增的,所以只观察不相同的结果) 发现:ans = x/2-2 || x/2-1 再把所有结果不同 && x/2-1的值打出来 发现 sqrt(x) &1 == 1 得到:ans = x/2-

HDU 4279 Number 坑爹的迷之精度

题目描述 首先定义"special number": 如果对于一个数字B,存在一个数字A(0<A<=B),并同时满足 B%A=0 和 gcd(A,B) != 1 ,那么我们就说A是B的"special number". 再定义一个函数f(x)表示x的"special number"的数量.并且如果f(x)%2=1时,我们就称x为"real number". 现在给你两个数字x和y且1<=x<=y<

HDU 4279 Number(数学题,找规律)

题目大意: 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

HDU 4279 Number(找规律)

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

hdu 4279&quot;Number&quot;(数论)

传送门 待参考资料: [1]:https://blog.csdn.net/u010709592/article/details/13615763 原文地址:https://www.cnblogs.com/violet-acmer/p/10676924.html

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

KMP算法的定义及KMP练手题 HDU 1711 Number Sequence (我的模板代码)

题意:就是要你来找出b数组在a数组中最先匹配的位置,如果没有则输出-1 思路:直接KMP算法(算法具体思想这位牛写的不错http://blog.csdn.net/v_july_v/article/details/7041827) AC代码: #include<cstdio> #include<cstring> #include<stdlib.h> #include<iostream> using namespace std; #define maxn 100

hdu 5014 Number Sequence(贪心)

题目链接:hdu 5014 Number Sequence 题目大意:给定n,表示有0~n这n+1个数组成的序列a,要求构造一个序列b,同样是由0~n组成,要求∑ai⊕bi尽量大. 解题思路:贪心构造,对于n来说,找到n对应二进制的取反对应的数x,那么从x~n之间的数即可两两对应,然后x-1即是一个子问题. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; con

HDU 5014 Number Sequence(西安网络赛H题)

HDU 5014 Number Sequence 题目链接 思路:对于0-n,尽量不让二进制中的1互相消掉就是最优的,那么只要两个数只要互补就可以了,这样每次从最大的数字,可以找到和他互补的数字,然后这个区间就能确定了,然后剩下的递归下去为一个子问题去解决 代码: #include <cstdio> #include <cstring> const int N = 100005; int n, a[N], ans[N]; int cnt[N]; int count(int x) {