fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. string Cong(string a, string b)
  6. {
  7. int len = max(a.length(), b.length());
  8. while (a.length()<len)
  9. a="0"+a;
  10. while (b.length()<len)
  11. b="0"+b;
  12. /*
  13.   a = 123
  14.   b = 4567
  15.   ->
  16.   a = 0123
  17.   b = 4567
  18.   */
  19. string rs = "";
  20. int remember = 0;
  21. for (int i=len-1; i>=0; i--)
  22. {
  23. int n1 = a[i]-'0';
  24. int n2 = b[i]-'0';
  25. int s = n1+n2+remember;
  26.  
  27. char rs_tmp = s%10 + '0';
  28. rs = rs_tmp + rs;
  29. remember = s/10;
  30. }
  31. if (remember!=0)
  32. return char(remember+'0')+rs;
  33. return rs;
  34. }
  35.  
  36. string luythua(string x, int n, int d)
  37. {
  38. if (n==0) return "1";
  39. else if (n==1) return x;
  40. string rs = x;
  41. for (int i=2; i<=n; i++)
  42. {
  43. string rs_tmp = rs;
  44. for (int j=2; j<=d; j++)
  45. {
  46. rs = Cong(rs, rs_tmp); //2^3 = ((2)*2)*2
  47. }
  48. }
  49. return rs;
  50. }
  51.  
  52. int main()
  53. {
  54. int n, m;
  55. cin>>n>>m;
  56. string lt2 = luythua("2", n, 2);
  57. string lt3 = luythua("3", m, 3);
  58.  
  59. string S = Cong(lt2, lt3);
  60.  
  61. cout<<S[0];
  62. return 0;
  63. }
Success #stdin #stdout 0s 4356KB
stdin
4 2
stdout
2