Run ID:90870

提交时间:2024-09-17 18:38:15

#include<iostream> using namespace std; bool is_prime(int tar){ //判断是否为prime int i = 2; while(i <= sqrt(float(tar))){ if(tar % i == 0) return false; i++; } return true; } int rev_int(int tar){//求逆序数 int res = 0; while(tar!=0){ res = res * 10 + tar % 10; tar = tar / 10; } return res; } int main(){ int M, N; cin>>M>>N; bool isfirst = true; for(int i = M; i < N; i++){ if(is_prime(i) && is_prime(rev_int(i))){ if(!isfirst) cout<<','; cout<<i; isfirst = false; } } printf("\n"); return 0; }