booldigit_count_check(longlong num){ if (num == 11) returntrue; // 11是特例要先处理 int digit_count = (int)log10(num); if (digit_count % 2 != 0) returnfalse; elsereturntrue; }
boolis_pal(longlong num){ longlong origin = num; longlong reserved = 0; while (num != 0) { int temp = num % 10; reserved = reserved * 10 + temp; num /= 10; } return origin == reserved; }
boolis_prime(longlong num){ bool status = true; for (int i=2; i * i <= num; i++) { if (num % i == 0) { status = false; break; } } if (num == 1) status = false; return status; }
intmain(){ longlong a,b,num; cin >> a >> b; for (int i=a/2*2+1; i <= b; i += 2) { if (!digit_count_check(i)) continue; if (!is_pal(i)) continue; if (is_prime(i)) cout << i << endl; } return0; }
boolis_prime(longlong num){ bool status = true; for (int i=2; i * i <= num; i++) { if (num % i == 0) { status = false; break; } } if (num == 1) status = false; return status; }