Codeforces--1051B--Relatively Prime Pairs

73 篇文章 0 订阅

题目描述:
You are given a set of all integers from l to r inclusive, l<r, (r−l+1)≤3⋅105 and (r−l) is always odd.

You want to split these numbers into exactly r−l+12 pairs in such a way that for each pair (i,j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.

Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
输入描述:
The only line contains two integers l and r (1≤l<r≤1018, r−l+1≤3⋅105, (r−l) is odd).
输出描述:
If any solution exists, print “YES” in the first line. Each of the next r−l+12 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r−l+1) numbers should be pairwise distinct and should have values from l to r inclusive.

If there are multiple solutions, print any of them.

If there exists no solution, print “NO”.
输入:
4
8 5 2 3
6
1 1 1 2 2 2
输出:
164
27
题意:
问在区间内有多少对数互为质数。
题解
一个数和他相邻的数一定是互为质数,枚举即可。
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long ll;

int main(){
    ll l,r;
    while(scanf("%lld%lld",&l,&r)!=EOF){
        printf("YES\n");
        for(ll i = l;i < r;i += 2){
            printf("%I64d %I64d\n",i,i + 1);
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值