2 条题解

  • 2
    @ 2023-3-31 20:46:07
    #include<iostream>
    #include<math.h>
    using namespace std;
    int n,cnt;
    bool check1(int x){//判断质数
    	for(int i=2;i*i<=x;i++){
    		if(x%i==0)return false;
    	}
    	return true;
    }
    bool check2(int x){//判断回文数
    	int k=0,tmp=x;
    	while(tmp){
    		k=k*10+tmp%10;//合成倒序数,判断相等
    		tmp/=10;
    	}
    	if(k==x)return true;
    	else return false;
    }
    int main(){
    	cin>>n;
    	for(int i=11;i<=n;i++){
    		if(check1(i)&&check2(i))cnt++;
    	}
    	cout<<cnt;
    	return 0;
    }
    
    • 0
      @ 2023-5-28 19:38:29

      #include<bits/stdc++.h> using namespace std; bool f(int n) { if(n<=1) return false; for(int i=2;ii<=n;i++) if(n%i==0) return false; return true; } bool x(int n) { int s=0,b=n; while(n) { s=s10+n%10; n/=10; } if(s==b) return true; return false; } int main() { int n,s=0; cin>>n; for(int i=11;i<=n;i++) if(f(i)&&x(i)) s++; cout<<s; return 0;

      1. }
      • 1

      信息

      ID
      948
      时间
      1000ms
      内存
      128MiB
      难度
      5
      标签
      递交数
      201
      已通过
      80
      上传者