5 solutions

  • 3
    @ 2025-2-11 9:08:06
    #include<bits/stdc++.h>
    using namespace std;
    int v[100]; 
    int main()
    {
    	int n,m;
    	cin>>n>>m;
    	int cnt=0;//满足条件的数的个数 
    	for(int i=n;i<=m;i++)
    	{
    		int t=i;
    		int idx=0;
    		bool st=true;//最开始满足要求 
    		while(t)
    		{
    			int ge=t%9;
    			if(ge%2==0)
    			{
    				st=false; //只要存在一个偶数 
    			}
    			v[idx++]=ge;//短除法
    			t/=9; 
    		}
    		idx--;
    		bool st1=true;
    		for(int j=0,k=idx;j<k;j++,k--) //判断回文 
    		{
    			if(v[j]!=v[k]) st1=false;	
    		} 
    		if(st1&&st)
    		{
    			cnt++;
    		}
    	}
    	cout<<cnt<<endl;
    	return 0;
    }
    
    
    • 2
      @ 2025-2-28 20:03:33
      #include<bits/stdc++.h>
      using namespace std;
      bool check(int x)
      {
      	vector<int> v;
      	while(x)
      	{
      		int ge=x%9;
      		v.push_back(ge);
      		if(ge%2==0)
      		{
      			return false;
      		}
      		x/=9;
      	}
      	vector<int> v1=v;
      	reverse(v1.begin(),v1.end());
      	if(v1==v)
      	{
      		return true;
      	}
      	return false;
      }
      int main()
      {
      	int n,m;
      	cin>>n>>m;
      	int cnt=0;
      	for(int i=n;i<=m;i++)
      	{
      		if(check(i))
      		{
      			cnt++;
      		}
      	}
      	cout<<cnt;
      	return 0;
      }
      
      • 1
        @ 2025-2-28 20:01:28
        #include<bits/stdc++.h>
        using namespace std;
        bool check(int x)
        {
        	vector<int> v;
        	while(x)
        	{
        		int ge=x%9;
        		v.push_back(ge);
        		if(ge%2==0) return false;
        		x/=9;
        	}
        	vector<int> v1=v;
        	reverse(v1.begin(),v1.end());
        	if(v1==v) return true;
        	return false;
        }
        int main()
        {
        	int n,m;
        	cin>>n>>m;
        	int cnt=0;
        	for(int i=n;i<=m;i++)
        	{
        		if(check(i))
        		{
        			cnt++;
        		}
        	}
        	cout<<cnt;
        	return 0;
        }
        
        
        • 1
          @ 2024-5-4 9:22:17
          #include<bits/stdc++.h>
          using namespace std;
          
          int main()
          {
          	int n,m;
          	cin>>n>>m;
          	int cnt=0;//满足条件的数的个数 
          	for(int i=n;i<=m;i++)
          	{
          		int t=i;
          		vector<int> v;
          		bool st=true;//最开始满足要求 
          		while(t)
          		{
          			int ge=t%9;
          			if(ge%2==0)
          			{
          				st=false; //只要存在一个偶数 
          			}
          			v.push_back(ge);//断除法
          			t/=9; 
          		}
          		vector<int> v1=v;
          		reverse(v1.begin(),v1.end());//翻转 
          		if(v1==v&&st)
          		{
          			cnt++;
          		}
          	}
          	cout<<cnt<<endl;
          	return 0;
          }
          
          • 0
            @ 2025-4-13 11:02:33
            #include <bits/stdc++.h>
            using namespace std;
            
            string to_base9(int x) {
                string s;
                if (x == 0) return "0";
                while (x > 0) {
                    s += (x % 9) + '0';
                    x /= 9;
                }
                reverse(s.begin(), s.end());
                return s;
            }
            
            int main() {
                int N, M;
                cin >> N >> M;
                int count = 0;
                for (int x = N; x <= M; ++x) {
                    string s = to_base9(x);
                    bool all_odd = true;
                    for (char c : s) {
                        if (c != '1' && c != '3' && c != '5' && c != '7') {
                            all_odd = false;
                            break;
                        }
                    }
                    if (!all_odd) continue;
                    if (s == string(s.rbegin(), s.rend())) {
                        count++;
                    }
                }
                cout << count << endl;
                return 0;
            }
            
            • 1

            Information

            ID
            680
            Time
            1000ms
            Memory
            256MiB
            Difficulty
            5
            Tags
            # Submissions
            58
            Accepted
            20
            Uploaded By