C - Coprime 2

Given a sequence of NN positive integers A=(A_1,A_2,\dots,A_N)A=(A1​,A2​,…,AN​), find every integer kk between 11 and MM (inclusive) that satisfies the following condition:

  • \gcd(A_i,k)=1gcd(Ai​,k)=1 for every integer ii such that 1 \le i \le N1≤i≤N.

Constraints

  • All values in input are integers.
  • 1 \le N,M \le 10^51≤N,M≤105
  • 1 \le A_i \le 10^51≤Ai​≤105

Input

Input is given from Standard Input in the following format:

NN MM
A_1A1​ A_2A2​ \dots… A_NAN​

Output

In the first line, print xx: the number of integers satisfying the requirement.
In the following xx lines, print the integers satisfying the requirement, in ascending order, each in its own line.

Sample 1

InputcopyOutputcopy
3 12
6 1 5
3
1
7
11

For example, 77 has the properties \gcd(6,7)=1,\gcd(1,7)=1,\gcd(5,7)=1gcd(6,7)=1,gcd(1,7)=1,gcd(5,7)=1, so it is included in the set of integers satisfying the requirement.
On the other hand, 99 has the property \gcd(6,9)=3gcd(6,9)=3, so it is not included in that set.
We have three integers between 11 and 1212 that satisfy the condition: 11, 77, and 1111. Be sure to print them in ascending order.

思路:取质因数,筛掉倍数,剩下的就是答案

/*Where there is light, in my heart.*/
/*SUMMER_TRAINING DAY 15*/
#include<bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
//
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f
#define ll long long
//#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define unmap(a,b) unordered_map<a,b>
#define unset(a) unordered_set<a>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
#define mode 1e4+7
#define pi acos(-1)
typedef double db;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> vi;
const int N=2e5+5;
//
int mark[N];
int a[N];
int n,m;
// 
signed main(){
	mem(mark,0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	set<int> s;
	for(int i=1;i<=n;i++){
		for(int j=1;j*j<=a[i];j++){//记录因子;
		    if(a[i]%j==0){
				if(j>1) s.insert(j);
				if(a[i]/j>1) s.insert(a[i]/j);
			}
		}
	}
	for(auto i:s){
		for(int j=i;j<=m;j+=i){//累加倍数;
			mark[j]=1;
		}
	}
	vector<int> ans;
	for(int i=1;i<=m;i++){
		if(!mark[i]) ans.pb(i);
	}
	cout<<ans.size()<<endl;
	for(auto i:ans){
		cout<<i<<endl;
	}
}                
//made by shun 20220718

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,根据您的要求,我可以给您提供一个大致的程序框架,您可以在此基础上进行修改和完善。以下是程序框架: ```c #include <stdio.h> #include <stdlib.h> // 定义学生结构体 typedef struct { int id; // 学生编号 float score; // 学生成绩 } Student; // 定义链表节点结构体 typedef struct Node { Student data; // 学生信息 struct Node* next; // 指向下一个节点的指针 } Node; // 定义链表指针类型 typedef Node* List; // 初始化链表 void initList(List* plist); // 在链表末尾添加节点 void addNode(List* plist, Student stu); // 查询某个学生的成绩是否为素数 void prime(List list, int id); // 查询某两个学生的成绩是否互质/互素 void coprime(List list, int id1, int id2); // 根据 GPA 对学生成绩进行考情分析 void analyzeGPA(List list); int main() { List list; initList(&list); int choice; do { printf("1. 添加学生信息\n"); printf("2. 查询学生成绩是否为素数\n"); printf("3. 查询学生成绩是否互质/互素\n"); printf("4. 根据 GPA 进行考情分析\n"); printf("5. 退出程序\n"); printf("请选择操作:"); scanf("%d", &choice); switch (choice) { case 1: // 添加学生信息 break; case 2: // 查询学生成绩是否为素数 break; case 3: // 查询学生成绩是否互质/互素 break; case 4: // 根据 GPA 进行考情分析 break; case 5: // 退出程序 break; default: printf("输入有误,请重新选择!\n"); break; } } while (choice != 5); return 0; } void initList(List* plist) { // 初始化链表 } void addNode(List* plist, Student stu) { // 在链表末尾添加节点 } void prime(List list, int id) { // 查询某个学生的成绩是否为素数 } void coprime(List list, int id1, int id2) { // 查询某两个学生的成绩是否互质/互素 } void analyzeGPA(List list) { // 根据 GPA 对学生成绩进行考情分析 } ``` 您可以根据需求进行添加、修改和完善。希望能对您有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值