1.2.5Dual Palindromes

  
    
  1. /*
  2. ID: awsd1231
  3. PROG: dualpal
  4. LANG: C++
  5. */
  6. #include<iostream>
  7. #include<cstdio>
  8. #include<cmath>
  9. #include<cstring>
  10. using namespace std;
  11. const int maxn = 33;
  12. int n, s;
  13. char mayPal[maxn] = {0};
  14. bool isPal(int xq) {
  15. int count = 0;
  16. for(int i = 2; i != 11; ++i) {
  17. int x = xq;
  18. memset(mayPal, 0, maxn);
  19. int idx = 0;
  20. bool canZero = false;
  21. for(int j = maxn; j != -1; --j) {
  22. if(!canZero && pow(i, j) > x) continue;
  23. else {
  24. canZero = true;
  25. for(int k = i-1; k != -1; --k) {
  26. if(k * pow(i, j) <= x) {
  27. mayPal[idx++] = k +'0';
  28. x -= k * pow(i, j);
  29. break;
  30. }
  31. }
  32. }
  33. }
  34. int len = strlen(mayPal);
  35. bool yes = true;
  36. for(int j = 0; j < len/2; ++j) {
  37. if(mayPal[j] != mayPal[len-j-1]) {
  38. yes = false;
  39. break;
  40. }
  41. }
  42. if(yes) {
  43. count++;
  44. }
  45. if(count == 2) return true;
  46. }
  47. return false;
  48. }
  49. int main() {
  50. freopen("dualpal.in" ,"r", stdin);
  51. freopen("dualpal.out", "w", stdout);
  52. cin >> n >> s;
  53. for(int i = s+1, t = 0; t != n; i++) {
  54. if(isPal(i)) {
  55. cout << i << endl;
  56. t++;
  57. }
  58. }
  59. return 0;
  60. }





你可能感兴趣的:(dual)