Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool isPrime(int n) {
- if (n < 2) return 0;
- for (int i = 2; i * i <= n; i++) {
- if (n % i == 0) return false;
- }
- return true;
- }
- bool isBinPal(int n) {
- string s;
- while (n) {
- s += (n % 2) + '0';
- n /= 2;
- }
- for (int i = 0; i < (int) s.size(); i++) {
- if (s[i] != s[(int) s.size() - i - 1]) return false;
- }
- return true;
- }
- int main() {
- int cnt = 0;
- for (int i = 1; i <= 9; i++)
- for (int j = 0; j <= 9; j++) {
- int n = i * 100 + j * 10 + i;
- if (isBinPal(n)) {
- cnt++;
- cout << cnt << ' ' << n << ' ';
- if (n <= (1 << 9)) cout << bitset<9>(n);
- else cout << bitset<10>(n);
- if (isPrime(n)) cout << " la so bi an can tim";
- cout << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement