Codeforces Round #749(Div. 1+Div. 2, based on Technocup 2022 Elimination Round1)-A. Windblume Ode-题解

本文主要是介绍Codeforces Round #749(Div. 1+Div. 2, based on Technocup 2022 Elimination Round1)-A. Windblume Ode-题解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

    • Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) - A. Windblume Ode
      • Problem Description
      • Input
      • Output
      • Sample Input
      • Sample Onput
      • Note
  • 题目大意
  • 解题思路
  • AC代码

Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) - A. Windblume Ode

传送门
Time Limit: 1 seconds
Memory Limit: 256 megabytes

Problem Description

A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.

You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of n ( n ≥ 3 ) n (n≥3) n(n3) positive distinct integers (i.e. different, no duplicates are allowed).

Find the largest subset (i.e. having the maximum number of elements) of this array such that its sum is a composite number. A positive integer x x x is called composite if there exists a positive integer y y y such that 1 < y < x 1<y<x 1<y<x and x x x is divisible by y y y.

If there are multiple subsets with this largest size with the composite sum, you can output any of them. It can be proven that under the constraints of the problem such a non-empty subset always exists.

Input

Each test consists of multiple test cases. The first line contains the number of test cases t ( 1 ≤ t ≤ 100 ) t (1≤t≤100) t(1t100). Description of the test cases follows.

The first line of each test case contains an integer n ( 3 ≤ n ≤ 100 ) n (3≤n≤100) n(3n100) — the length of the array.

The second line of each test case contains n distinct integers a 1 , a 2 , … , a n ( 1 ≤ a i ≤ 200 ) a_1,a_2,…,a_n (1≤a_i≤200) a1,a2,,an(1ai200) — the elements of the array.

Output

Each test case should have two lines of output.

The first line should contain a single integer x x x: the size of the largest subset with composite sum. The next line should contain x x x space separated integers representing the indices of the subset of the initial array.

Sample Input

4
3
8 1 2
4
6 9 4 2
9
1 2 3 4 5 6 7 8 9
3
200 199 198

Sample Onput

2
2 1
4
2 1 4 3
9
6 9 1 2 3 4 5 7 8
3
1 2 3 

Note

In the first test case, the subset a 2 , a 1 {a_2,a_1} a2,a1 has a sum of 9 9 9, which is a composite number. The only subset of size 3 3 3 has a prime sum equal to 11 11 11. Note that you could also have selected the subset a 1 , a 3 {a_1,a_3} a1,a3 with sum 8 + 2 = 10 8+2=10 8+2=10, which is composite as it’s divisible by 2 2 2.

In the second test case, the sum of all elements equals to 21, which is a composite number. Here we simply take the whole array as our subset.


题目大意

  • 给你 n n n个数,你可以从中删除其中几个数,使得剩下的所有的数之不是素数。

  • 如果有多种删法,找出能够保留更多元素的一种删法,并输出保留的元素的个数及下标。

解题思路

给你的数的个数 n n n ≥ 3 \geq3 3的,所以 n n n个数的和 ≥ 6 \geq6 6。因此我们只需要看这 n n n个数的和是否为偶数

  • 若和是偶数,直接就不是素数,一个都不用删,全部保留即可。
  • 若和是奇数,其中必定包含某个数也是奇数,随便找到一个并删除即可。

AC代码

#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
bool isPrime[20010] = {0, 0, 0}; // isPrime[n]代表n是否为素数
bool Prime(int n) { // 返回一个数n是否为素数for (int i = 2; i * i <= n; i++) {if (n % i == 0) {return false;}}return true;
}
void init() { // 初始化,提前计算出20000以内的所有素数for (int i = 3; i <= 20000; i++) {isPrime[i] = Prime(i);}
}
int a[111]; // 用来储存输入的数
int main() {init(); // 初始化int N;cin>>N; // N组测试用例while(N--) {int n; cd(n); // scanf("%d", &n); 这个测试用例有n个数int s = 0;for (int i = 0;i<n;i++) {cd(a[i]); // scanf("%d", &a[i]);s+=a[i]; // 求和}if (!isPrime[s]) { // 本来就不是素数,一个都不用删,直接输出即可printf("%d\n", n);for (int i = 1; i <= n; i++) {printf("%d ", i);}puts("");}else { // 本来是质数,只需要删掉一个奇数即可int del = 0; // 要删除的数的下标for (int i = 0; i < n; i++) {if (a[i] % 2) { // 如果这个数是奇数del = i + 1; // 记录下它是第几个数(存的时候是从0开始存的)break; // 找到一个就不用继续找了}}printf("%d\n", n-1); // 剩下n-1个数for (int i = 1; i <= n; i++) {if (i != del) { // 不是要被删除的那个数printf("%d ", i); // 就输出}}puts(""); // 换行}}return 0;
}

原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/120835252

这篇关于Codeforces Round #749(Div. 1+Div. 2, based on Technocup 2022 Elimination Round1)-A. Windblume Ode-题解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/893883

相关文章

Retrieval-based-Voice-Conversion-WebUI模型构建指南

一、模型介绍 Retrieval-based-Voice-Conversion-WebUI(简称 RVC)模型是一个基于 VITS(Variational Inference with adversarial learning for end-to-end Text-to-Speech)的简单易用的语音转换框架。 具有以下特点 简单易用:RVC 模型通过简单易用的网页界面,使得用户无需深入了

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

C++ | Leetcode C++题解之第393题UTF-8编码验证

题目: 题解: class Solution {public:static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num &

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

C语言 | Leetcode C语言题解之第393题UTF-8编码验证

题目: 题解: static const int MASK1 = 1 << 7;static const int MASK2 = (1 << 7) + (1 << 6);bool isValid(int num) {return (num & MASK2) == MASK1;}int getBytes(int num) {if ((num & MASK1) == 0) {return

C - Word Ladder题解

C - Word Ladder 题解 解题思路: 先输入两个字符串S 和t 然后在S和T中寻找有多少个字符不同的个数(也就是需要变换多少次) 开始替换时: tips: 字符串下标以0开始 我们定义两个变量a和b,用于记录当前遍历到的字符 首先是判断:如果这时a已经==b了,那么就跳过,不用管; 如果a大于b的话:那么我们就让s中的第i项替换成b,接着就直接输出S就行了。 这样

CSS实现DIV三角形

本文内容收集来自网络 #triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;} #triangle-down {width: 0;height: 0;bor