【思维+数论】SDUT 2499 数字

 Problem Description

定义f(x) = {比x小,不可以被x整除并且不和x互质的数的个数}(x为正整数)。

当f(x) 是奇数的时候我们称x为“奇真数”。

给出两个数x,y求区间[x,y]内的“奇真数”的个数。

Input

 第一行输入一个数N代表测试数据个数(N<=20)。接下来N行每行两个正整数x , y ( 0 < x <= y < 2^31)。

Output

 对于每个测试数据输出“奇真数”的个数,每行输出一个结果。

Sample Input

2
1 1
1 10

Sample Output

0
4

误:

这个题,题目描述有点问题,举个栗子:5比20小,5还能被20整除?所以开头那一句应该是不可以整除x。

(这题只做java练习而放这里不大合适...做比赛题的话还说得过去,拿来考试现做的话就不大现实了,只能是背下来...)

思路:

(脑子不够使得...还是写一下逻辑结构)

1.分析题目:此f(x)非上面所指

①在x某范围内,f(x)运算结果为true的个数如果是奇数,计数器++。

②计算f(x):设符合(我们要找个数的)数的条件为i,那么,不可整除x:i不是x的约数;不与x互质:i与x有公约数

2.要在所有数中排除这两种情况。

3.两种情况是否有交集?如果3是6的约数,那么3与6有本身作为公约数,于是i与x不互质。所以没有交集。f(x)=x-互质-约数+1

4.具体讨论两种情况如何实现,这一步骤在大佬这讲得很清楚了:https://blog.csdn.net/tclh123/article/details/7970545

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		long  x,y;
		while(n-->0)
		{
			x=s.nextInt();
			y=s.nextInt();
			System.out.println(f(y)-f(x-1));
		}
		s.close();
	}
	static long f(long a)
	{
		if(a<=2)
			return 0;
		if((long)Math.sqrt(a)%2==1)
			return a/2-1;
		else 
			return a/2-2;
	}
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Problem_C_Data.zip The three data sets provided contain product user ratings and reviews extracted from the Amazon Customer Reviews Dataset thru Amazon Simple Storage Service (Amazon S3). hair_dryer.tsv microwave.tsv pacifier.tsv Data Set Definitions: Each row represents data partitioned into the following columns. Problem_C_Data.zip提供的三个数据集包含产品用户评分和通过Amazon Simple Storage Service(Amazon S3)从Amazon客户评论数据集提取的评论。 hair_dryer.tsv微波.tsv pacifier.tsv数据集定义:每行代表划分为以下各列的数据。 ● marketplace (string): 2 letter country code of the marketplace where the review was written. ●市场(字符串):撰写评论的市场的2个字母的国家代码。 ● customer_id (string): Random identifier that can be used to aggregate reviews written by a single author. ●customer_id(字符串):随机标识符,可用于汇总单个作者撰写的评论。 ● review_id (string): The unique ID of the review. ●review_id(字符串):评论的唯一ID。 ● product_id (string): The unique Product ID the review pertains to. ●product_id(字符串):审核所属的唯一产品ID。 ● product_parent (string): Random identifier that can be used to aggregate reviews for the same product. ●product_parent(字符串):随机标识符,可用于汇总同一产品的评论。 ● product_title (string): Title of the product. ●product_title(字符串):产品的标题。 ● product_category (string): The major consumer category for the product. ●product_category(字符串):产品的主要消费者类别。 ● star_rating (int): The 1-5 star rating of the review. ●star_rating(int):评论的1-5星评级。 ● helpful_votes (int): Number of helpful votes. ●helpful_votes(int):有用的投票数。 ● total_votes (int): Number of total votes the review received. ●total_votes(int):评论收到的总票数。 ● vine (string): Customers are invited to become Amazon Vine Voices based on the trust that they have earned in the Amazon community for writing accurate and insightful reviews. Amazon provides Amazon Vine members with free copies of products that have been submitted to the program by vendors. Amazon doesn't influence the opinions of Amazon Vine members, nor do they modify or edit reviews. ●vine(字符串):基于客户在撰写准确而有见地的评论方面所获得的信任,邀请客户成为Amazon Vine Voices。亚马逊为Amazon Vine成员提供了供应商已提交给该程序的产品的免费副本。Amazon不会影响Amazon Vine成员的意见,也不会修改或编辑评论。 ● verified_purchase (string): A “Y” indicates Amazon verified that the person writing the review purchased the product at Amazon and didn't receive the product at a deep discount. ●verify_purchase(字符串):“ Y”表示亚马逊已验证撰写评论的人在亚马逊上购买了该产品,并且没有以大幅折扣收到该产品。 ● review_headline (string): The title of the review. ●review_headline(字符串):评论的标题。 ● review_body (string): The review text. ●review_body(字符串):评论文本。 ● review_date (bigint): The date the review was written. ●review_date(bigint):撰写评论的日期。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值