//找质数,找能除的质数
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<time.h>
#include<math.h>
using namespace std;
struct bign
{
int d[1001];
int length;
bign()
{
memset(d, 0, sizeof(d));
length = 0;
}
};
bign change(char str[])
{
bign a;
a.length = strlen(str);
for (int i = 0; i < a.length; i++)
{
a.d[i] = str[a.length - i - 1] - '0';
}
return a;
}
bign add(bign a, bign b)
{
bign c;
int carry = 0;
for (int i = 0; i < a.length||i<b.length; i++)
{
int temp = a.d[i] +b.d[i] + carry;
c.d[c.length++] = temp % 10;
carry = temp / 10;
}
if (carry != 0)
{
c.d[c.length++] = carry;
}
return c;
}
bool judge(bign a)
{
for (int i = 0; i <= a.length / 2; i++)
{
if (a.d[i] != a.d[a.length - 1 - i])
return false;
}
return true;
}
void print(bign a)
{
for (int i = a.length - 1; i >= 0; i--)
{
cout << a.d[i];
}
}
int main()
{
char c[1001];
int count = 0, m;
cin >> c >> m;
bign a = change(c);
while (!judge(a)&&count<m)
{
bign b = a;
reverse(b.d, b.d + b.length);
a = add(a, b);
count++;
}
print(a);
cout << endl << count;
}
A1024 Palindromic Number [回文+大整数加法]
最新推荐文章于 2022-07-27 22:16:54 发布