7 条题解

  • 0
    @ 2025-11-20 20:18:09
    本人打的AC代码,请各位大佬指点
    
    # include <bits/stdc++.h>
    
    using namespace std;
    bool IsPrime(int x){
    	if(x<2)return false;
    	if(x==2)return true;
    	for(int i = 2;i*i<=x;i++)
    		if(x%i==0)
    		    return false;
    	return true;
    }
    bool HasD(int n,int d){
    	while(n>0){
    		if(n%10==d)return true;
    		n/=10;
    	}
    	return false;
    }
    int main(){
    	int a,b,d,tot=0;
    	cin>>a>>b>>d;
    	for(int i = a;i<=b;i++){
    		if(HasD(i,d)&&IsPrime(i))tot++;
    	}
    	cout<<tot<<"\n";
    	return 0;
    }
    

    信息

    ID
    975
    时间
    1000ms
    内存
    128MiB
    难度
    6
    标签
    递交数
    456
    已通过
    134
    上传者