Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- unsigned func (unsigned x1, unsigned x2, unsigned k)
- {
- if (k == 1)
- return 0;
- x1 /= 10;
- x2 = x1 % 10;
- return x2 * k / 10 + func (x1, x2, k / 10);
- }
- unsigned count (unsigned x)
- {
- if (x < 10)
- return 1;
- return (count (x / 10) + 1);
- }
- unsigned rev (unsigned x)
- {
- unsigned res, k, i, j, power, y, N;
- k = count (x);
- power = 1;
- for (j = 1; j < k; j++)
- power *= 10;
- if (power == 1)
- res = x;
- else
- {
- y = x % 10;
- res = func (x*10, y, power*10);
- }
- return res;
- }
- int main(void)
- {
- unsigned x, res, k, i, j, power, y, N;
- scanf("%u %u", &x, &N);
- for (i = 0; i < N ; i++)
- {
- x += rev (x);
- }
- if (x == rev (x))
- printf("Yes\n%u\n", x);
- else
- printf("No\n");
- return 0;
- }
Add Comment
Please, Sign In to add comment