Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- bool first_last(int n) {
- int last = n % 10;
- int first = n;
- while (first > 9) {
- first /= 10;
- }
- return first == last;
- }
- int main() {
- int n, k;
- cin >> k >> n;
- vector<bool> nums(n + 1, true);
- for (ll i = 2; i < n + 1; ++i) {
- if (nums[i]) {
- for (ll j = i * i; j < n + 1; j += i)
- nums[j]= false;
- }
- }
- bool flag = true;
- for (int i = k; i <= n; ++i) {
- if (nums[i] && first_last(i)) {
- cout << i << " ";
- flag = false;
- }
- }
- if (flag) cout << 0;
- // return 0;
- }
- // ----------------------------------------------------------
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- bool odd_sum(int n) {
- int sum = 0;
- while (n > 9) {
- sum += n % 10;
- n /= 10;
- }
- return (sum + n) % 2 == 0;
- }
- int main() {
- int n, k;
- cin >> k >> n;
- vector<bool> nums(n + 1, true);
- for (ll i = 2; i < n + 1; ++i) {
- if (nums[i]) {
- for (ll j = i * i; j < n + 1; j += i)
- nums[j]= false;
- }
- }
- bool flag = true;
- for (int i = k; i <= n; ++i) {
- if (nums[i] && odd_sum(i)) {
- cout << i << " ";
- flag = false;
- }
- }
- if (flag) cout << 0;
- // return 0;
- }
- // --------------------------------------------------------------
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- bool odd_sum(int n) {
- int prev = n % 10;
- int cur;
- while (n > 9) {
- n /= 10;
- cur = n % 10;
- if (cur <= prev) {
- return false;
- }
- prev = cur;
- }
- return true;
- }
- int main() {
- int n, k;
- cin >> k >> n;
- vector<bool> nums(n + 1, true);
- for (ll i = 2; i < n + 1; ++i) {
- if (nums[i]) {
- for (ll j = i * i; j < n + 1; j += i)
- nums[j]= false;
- }
- }
- bool flag = true;
- for (int i = k; i <= n; ++i) {
- if (nums[i] && odd_sum(i)) {
- cout << i << " ";
- flag = false;
- }
- }
- if (flag) cout << 0;
- // return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement