Submission
Status:
PPPPPPPPPPPPPPPPPPPP
Score: 100
User: NJTYTYTY
Problemset: จำนวนเฉพาะก่อนหน้า
Language: cpp
Time: 0.003 second
Submitted On: 2025-01-19 10:03:24
// string สลับฟันปลาเริ่มจาก 1
// #include<bits/stdc++.h>
// using namespace std;
// int main() {
// ios::sync_with_stdio(false); cin.tie(0);
// string a, b, res;
// cin >> a >> b;
// int lenA = a.length();
// int lenB = b.length();
// int i = 0, j =0;
// while(i < lenA && j < lenB)
// {
// res += a[i++];
// res += b[j++];
// }
// if(res.length() != lenA + lenB)
// {
// if(lenA > lenB)
// {
// for( ;i < lenA ; ++i)
// res+= a[i];
// }else
// {
// for( ; j < lenB; ++j)
// res+= b[j];
// }
// }
// cout << res;
// return 0;
// }
// #include<bits/stdc++.h>
// using namespace std;
// void rev(vector<int> &arr)
// {
// int n = arr.size();
// for(int i = 0 ;i < n / 2 +1 ; ++i)
// {
// swap(arr[i] , arr[n - 1 -i]);
// }
// }
// int main()
// {
// ios::sync_with_stdio(false); cin.tie(0);
// vector<int> arr;
// int n;
// cin >> n;
// for(int i = 0 ; i < n; ++i)
// {
// int x;
// cin >> x;
// arr.push_back(x);
// }
//
// rev(arr);
// for(auto e: arr)
// cout << e << " ";
// }
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
// ฟังก์ชันตรวจสอบจำนวนเฉพาะ
bool isPrime(int num) {
if (num < 2) return false;
for (int i = 2; i <= sqrt(num); ++i) {
if (num % i == 0) return false;
}
return true;
}
int main() {
int N;
cin >> N; // รับค่า N
vector<int> primes;
for (int i = N - 1; i > 1 && primes.size() < 5; --i ) {
if (isPrime(i)) {
primes.push_back(i);
}
}
sort(primes.begin(), primes.end()); // เรียงลำดับจากน้อยไปมาก
for (int prime : primes) {
cout << prime << " ";
}
return 0;
}