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 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.

解题思路:

所有的real number即是大于4的不是偶数平方的偶数或者奇数平方的奇数。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define LL long long
using namespace std;
LL solve(LL n)
{
	if(n <= 4) return 0;
	LL res = (n - 4) / 2;
	LL t = sqrt(n);
	if(t & 1) res ++;
	return res;
}
int main()
{
	LL l, r;
	int T;
	scanf("%d", &T);
	while(T--)
	{
		cin>>l>>r;
		cout<< solve(r) - solve(l-1)<<endl;
	}
	return 0;
}
时间: 2024-07-31 16:19:33

HDU 4279 Number(数学题,找规律)的相关文章

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 4952 Number Transformation (找规律)

题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值,求出这个固定的值和K相乘就可以了, 为什么会趋于固定的值呢,因为最后虽然i在不断增长,但是x也是在增长的,每次的倍数会回退一个发现 有余数,然后再加上一个,所以趋于稳定. 官方题解: 1 #include <iostream> 2 #include <cstdio> 3 #includ

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-

hdu4952 Number Transformation(数学题 | 找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4952 Number Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 261    Accepted Submission(s): 117 Problem Description Teacher Mai has

HDU 1005 Number Sequence (数学规律)

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104190    Accepted Submission(s): 25232 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A

HDU 4861 Couple doubi(找规律|费马定理)

Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4861 Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of th

hdu 4861 Couple doubi (找规律 )

题目链接 可以瞎搞一下,找找规律 题意:两个人进行游戏,桌上有k个球,第i个球的值为1i+2i+?+(p−1)i%p,两个人轮流取,如果DouBiNan的值大的话就输出YES,否则输出NO. 分析:解题报告 1 #include <cstdio> 2 #include <iostream> 3 4 using namespace std; 5 int main() 6 { 7 int k, p; 8 while(cin>>k>>p) 9 { 10 if(k/

HDU 4927 Series (找规律+JAVA)

题目链接:HDU 4927 Series 题意:给出一串N个元素的序列,作为第一串序列,第二串序列是第二串序列相邻元素的查值(即Bi=Ai+1-Ai)...第三串....一直到第N-1串是序列中只有一个数. 刚开始想到模拟一发,WA了一把,推出公式,发现是二项展开的系数(正负交替).组合数,果断要大数,苦逼JAVA不会.和一起队友摸索着,又T了一发,再想到组合数的递推.终于A了 C(a-1,b)=C(a,b)*a/(b-a+1) AC代码: import java.math.BigInteger

HDU 4919 打表找规律 java大数 map 递归

== oeis: 点击打开链接 瞎了,x.mod(BigInteger.ValueOf(2)).equal( BigInteger.ValueOf(1)) 写成了 x.mod(BigInteger.ValueOf(2)).equal( 1 ) T^T100块没了... import java.math.*; import java.util.*; import static java.lang.System.out; import java.io.*; public class Main { s