fork download
  1. #include <iostream>
  2. #define ull unsigned long long
  3. using namespace std;
  4.  
  5. ull zamien(string s, size_t x)
  6. {
  7. ull q=1;
  8. ull wynik = 0;
  9. for(int i=s.size()-1; i>=0; i--)
  10. {
  11. if(s[i]>='0' && s[i]<='9') wynik = wynik + (unsigned long long)(s[i]-48)*q;
  12. else wynik = wynik + (unsigned long long)(s[i]-55)*q;
  13. q*=x;
  14. }
  15. return wynik;
  16. }
  17.  
  18. string back(ull x, size_t a)
  19. {
  20. string odp;
  21. while(x)
  22. {
  23. if(x%a<10) odp = char((x%a)+48) + odp;
  24. else odp = char((x%a)+55) + odp;
  25. x/=a;
  26. }
  27. return odp;
  28. }
  29.  
  30. size_t test(string s1, string s2, string s3)
  31. {
  32. char x = '.';
  33. for(size_t i=0; i<s1.size(); i++) if(s1[i]>x) x=s1[i];
  34. for(size_t i=0; i<s2.size(); i++) if(s2[i]>x) x=s2[i];
  35. for(size_t i=0; i<s3.size(); i++) if(s3[i]>x) x=s3[i];
  36. if(x>='0' && x<='9') return (unsigned int)(x)-47;
  37. else return (unsigned int)(x)-54;
  38. }
  39.  
  40. int main()
  41. {
  42. string s1,s2,s3;
  43. ull a,b;
  44. while(cin>>s1>>s2>>s3)
  45. {
  46. for(size_t i=test(s1,s2,s3); i<17; i++)
  47. {
  48. a=zamien(s1,i);
  49. b=zamien(s2,i);
  50. cout << a << " " << b << "\n";
  51. if(back(a*b,i)==s3) cout << i << ' ';
  52. }
  53. cout << "\n";
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 4472KB
stdin
2 0 0
stdout
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0
2 0