死循环求助
查看原帖
死循环求助
977778
__Harry_Haiyun__楼主2023/8/4 10:41
#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define ui unsigned int
using namespace std;
const int maxn = 1e6+9;
string change(int n,int s)
{
    if (s == 10)
    {
        queue<int>st;
        while (n)
        {
            st.push(n % s);
            n /= s;
        }
        string str = "";
        while (!st.empty())
        {
            str += st.front();
            st.pop();
        }
        return str;
    }
    stack<int>st;
    while (n)
    {
        st.push(n % s);
        n /= s;
    }
    string str = "";
    while (!st.empty())
    {
        str += st.top();
        st.pop();
    }
    return str;
}
int stoi(string s)
{
    int plus = 1,sum = 0;
    for (int i = 0; i < s.length(); i++)
    {
        sum += plus * (s[i] + '0');
        plus *= 10;
    }
    return sum;
}
string to_string(int s)
{
    string str = "";
    while (s)
    {
        str += (s % 10 + '0');
        s /= 10;
    }
    return str;
}
bool isP(string n,int s)
{
    n = change(stoi(n),s);
    int left = 0,right = n.length() - 1;
    while (left <= right)
    {
        if (n[left] != n[right])
            return 0;
    }
    return 1;
}
int main()
{
	int n,s;
	cin >> n >> s;
	while (n)
	{
	    int cnt = 0;
	    bool flag = 0;
	    for (int i = 2; i <= 10; i++)
	    {
	        if (isP(to_string(s),i)) cnt++;
	        if (cnt == 2)
	        {
	            flag = 1;
	            break;
            }
        }
        if (flag) 
        {
            cout << s << '\n';
            n--;
        }
        s++;
    }
	return 0;
}
2023/8/4 10:41
加载中...