Advertisement
GerONSo

I 38

Jan 13th, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.63 KB | None | 0 0
  1. /*
  2.  
  3. ∧_∧
  4. ( ・ω・。)つ━☆・*。
  5. ⊂  ノ    ・゜
  6. しーJ   Accepted
  7.  
  8. */
  9.  
  10.  
  11.  
  12. // #pragma GCC optimize("O3")
  13. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  14.  
  15. #include <bits/stdc++.h>
  16. #include <ext/pb_ds/assoc_container.hpp>
  17. #include <ext/pb_ds/tree_policy.hpp>
  18.  
  19. #define ll long long
  20. #define all(x) begin(x), end(x)
  21. #define x first
  22. #define y second
  23. // #define int long long
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27.  
  28. typedef long double ld;
  29. template<typename T>
  30. using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  31.  
  32. const ld PI = atan2(0, -1);
  33.  
  34. void seriy() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. cout.tie(0);
  38. cout << fixed << setprecision(14);
  39. #ifdef _offline
  40. freopen("input.txt", "r", stdin);
  41. freopen("output.txt", "w", stdout);
  42. #endif
  43. }
  44.  
  45. const int MAXN = 10000 + 10;
  46. const int MAXL = 510;
  47. const int INF = 1e9 + 7;
  48. const int BASE = 47;
  49. const int MOD = 1e9 + 7;
  50. const int MAXLOG = 51;
  51. const ld EPS = 1e-6;
  52.  
  53. const int base = 1000000000;
  54. const int base_digits = 9;
  55.  
  56. struct Int {
  57.  
  58. vector<int> a;
  59. int sign;
  60.  
  61. /*<arpa>*/
  62.  
  63. int size(){
  64. if(a.empty()) return 0;
  65. int ans=(a.size()-1)*base_digits;
  66. int ca=a.back();
  67. while(ca)
  68. ans++,ca/=10;
  69. return ans;
  70. }
  71.  
  72. Int operator ^(const Int &v){
  73. Int ans=1,a=*this,b=v;
  74. while(!b.isZero()){
  75. if(b%2)
  76. ans*=a;
  77. a*=a,b/=2;
  78. }
  79. return ans;
  80. }
  81.  
  82. string to_string(){
  83. stringstream ss;
  84. ss << *this;
  85. string s;
  86. ss >> s;
  87. return s;
  88. }
  89.  
  90. int sumof(){
  91. string s = to_string();
  92. int ans = 0;
  93. for(auto c : s) ans += c - '0';
  94. return ans;
  95. }
  96.  
  97. /*</arpa>*/
  98.  
  99. Int() :
  100. sign(1) {
  101. }
  102.  
  103. Int(long long v) {
  104. *this = v;
  105. }
  106.  
  107. Int(const string &s) {
  108. read(s);
  109. }
  110.  
  111. void operator=(const Int &v) {
  112. sign = v.sign;
  113. a = v.a;
  114. }
  115.  
  116. void operator=(long long v) {
  117. sign = 1;
  118. a.clear();
  119. if (v < 0)
  120. sign = -1, v = -v;
  121. for (; v > 0; v = v / base)
  122. a.push_back(v % base);
  123. }
  124.  
  125. Int operator+(const Int &v) const {
  126. if (sign == v.sign) {
  127. Int res = v;
  128. for (int i = 0, carry = 0; i < (int) max(a.size(), v.a.size()) || carry; ++i) {
  129. if (i == (int) res.a.size())
  130. res.a.push_back(0);
  131. res.a[i] += carry + (i < (int) a.size() ? a[i] : 0);
  132. carry = res.a[i] >= base;
  133. if (carry)
  134. res.a[i] -= base;
  135. }
  136. return res;
  137. }
  138. return *this - (-v);
  139. }
  140.  
  141. Int operator-(const Int &v) const {
  142. if (sign == v.sign) {
  143. if (abs() >= v.abs()) {
  144. Int res = *this;
  145. for (int i = 0, carry = 0; i < (int) v.a.size() || carry; ++i) {
  146. res.a[i] -= carry + (i < (int) v.a.size() ? v.a[i] : 0);
  147. carry = res.a[i] < 0;
  148. if (carry)
  149. res.a[i] += base;
  150. }
  151. res.trim();
  152. return res;
  153. }
  154. return -(v - *this);
  155. }
  156. return *this + (-v);
  157. }
  158.  
  159. void operator*=(int v) {
  160. if (v < 0)
  161. sign = -sign, v = -v;
  162. for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
  163. if (i == (int) a.size())
  164. a.push_back(0);
  165. long long cur = a[i] * (long long) v + carry;
  166. carry = (int) (cur / base);
  167. a[i] = (int) (cur % base);
  168. //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
  169. }
  170. trim();
  171. }
  172.  
  173. Int operator*(int v) const {
  174. Int res = *this;
  175. res *= v;
  176. return res;
  177. }
  178.  
  179. void operator*=(long long v) {
  180. if (v < 0)
  181. sign = -sign, v = -v;
  182. for (int i = 0, carry = 0; i < (int) a.size() || carry; ++i) {
  183. if (i == (int) a.size())
  184. a.push_back(0);
  185. long long cur = a[i] * (long long) v + carry;
  186. carry = (int) (cur / base);
  187. a[i] = (int) (cur % base);
  188. //asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base));
  189. }
  190. trim();
  191. }
  192.  
  193. Int operator*(long long v) const {
  194. Int res = *this;
  195. res *= v;
  196. return res;
  197. }
  198.  
  199. friend pair<Int, Int> divmod(const Int &a1, const Int &b1) {
  200. int norm = base / (b1.a.back() + 1);
  201. Int a = a1.abs() * norm;
  202. Int b = b1.abs() * norm;
  203. Int q, r;
  204. q.a.resize(a.a.size());
  205.  
  206. for (int i = a.a.size() - 1; i >= 0; i--) {
  207. r *= base;
  208. r += a.a[i];
  209. int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()];
  210. int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1];
  211. int d = ((long long) base * s1 + s2) / b.a.back();
  212. r -= b * d;
  213. while (r < 0)
  214. r += b, --d;
  215. q.a[i] = d;
  216. }
  217.  
  218. q.sign = a1.sign * b1.sign;
  219. r.sign = a1.sign;
  220. q.trim();
  221. r.trim();
  222. return make_pair(q, r / norm);
  223. }
  224.  
  225. Int operator/(const Int &v) const {
  226. return divmod(*this, v).first;
  227. }
  228.  
  229. Int operator%(const Int &v) const {
  230. return divmod(*this, v).second;
  231. }
  232.  
  233. void operator/=(int v) {
  234. if (v < 0)
  235. sign = -sign, v = -v;
  236. for (int i = (int) a.size() - 1, rem = 0; i >= 0; --i) {
  237. long long cur = a[i] + rem * (long long) base;
  238. a[i] = (int) (cur / v);
  239. rem = (int) (cur % v);
  240. }
  241. trim();
  242. }
  243.  
  244. Int operator/(int v) const {
  245. Int res = *this;
  246. res /= v;
  247. return res;
  248. }
  249.  
  250. int operator%(int v) const {
  251. if (v < 0)
  252. v = -v;
  253. int m = 0;
  254. for (int i = a.size() - 1; i >= 0; --i)
  255. m = (a[i] + m * (long long) base) % v;
  256. return m * sign;
  257. }
  258.  
  259. void operator+=(const Int &v) {
  260. *this = *this + v;
  261. }
  262.  
  263. void operator-=(const Int &v) {
  264. *this = *this - v;
  265. }
  266.  
  267. void operator*=(const Int &v) {
  268. *this = *this * v;
  269. }
  270.  
  271. void operator/=(const Int &v) {
  272. *this = *this / v;
  273. }
  274.  
  275. Int operator ++(){
  276. *this += 1;
  277. return *this;
  278. }
  279.  
  280. Int operator ++(int){
  281. Int temp = *this;
  282. *this += 1;
  283. return temp;
  284. }
  285.  
  286. Int operator --(){
  287. *this -= 1;
  288. return *this;
  289. }
  290.  
  291. Int operator --(int){
  292. Int temp = *this;
  293. *this -= 1;
  294. return temp;
  295. }
  296.  
  297. bool operator<(const Int &v) const {
  298. if (sign != v.sign)
  299. return sign < v.sign;
  300. if (a.size() != v.a.size())
  301. return a.size() * sign < v.a.size() * v.sign;
  302. for (int i = a.size() - 1; i >= 0; i--)
  303. if (a[i] != v.a[i])
  304. return a[i] * sign < v.a[i] * sign;
  305. return false;
  306. }
  307.  
  308. bool operator>(const Int &v) const {
  309. return v < *this;
  310. }
  311.  
  312. bool operator<=(const Int &v) const {
  313. return !(v < *this);
  314. }
  315.  
  316. bool operator>=(const Int &v) const {
  317. return !(*this < v);
  318. }
  319.  
  320. bool operator==(const Int &v) const {
  321. return !(*this < v) && !(v < *this);
  322. }
  323.  
  324. bool operator!=(const Int &v) const {
  325. return *this < v || v < *this;
  326. }
  327.  
  328. void trim() {
  329. while (!a.empty() && !a.back())
  330. a.pop_back();
  331. if (a.empty())
  332. sign = 1;
  333. }
  334.  
  335. bool isZero() const {
  336. return a.empty() || (a.size() == 1 && !a[0]);
  337. }
  338.  
  339. Int operator-() const {
  340. Int res = *this;
  341. res.sign = -sign;
  342. return res;
  343. }
  344.  
  345. Int abs() const {
  346. Int res = *this;
  347. res.sign *= res.sign;
  348. return res;
  349. }
  350.  
  351. long long longValue() const {
  352. long long res = 0;
  353. for (int i = a.size() - 1; i >= 0; i--)
  354. res = res * base + a[i];
  355. return res * sign;
  356. }
  357.  
  358. friend Int gcd(const Int &a, const Int &b) {
  359. return b.isZero() ? a : gcd(b, a % b);
  360. }
  361.  
  362. friend Int lcm(const Int &a, const Int &b) {
  363. return a / gcd(a, b) * b;
  364. }
  365.  
  366. void read(const string &s) {
  367. sign = 1;
  368. a.clear();
  369. int pos = 0;
  370. while (pos < (int) s.size() && (s[pos] == '-' || s[pos] == '+')) {
  371. if (s[pos] == '-')
  372. sign = -sign;
  373. ++pos;
  374. }
  375.  
  376. for (int i = s.size() - 1; i >= pos; i -= base_digits) {
  377. int x = 0;
  378. for (int j = max(pos, i - base_digits + 1); j <= i; j++)
  379. x = x * 10 + s[j] - '0';
  380. a.push_back(x);
  381. }
  382. trim();
  383. }
  384.  
  385. friend istream& operator>>(istream &stream, Int &v) {
  386. string s;
  387. stream >> s;
  388. v.read(s);
  389. return stream;
  390. }
  391.  
  392. friend ostream& operator<<(ostream &stream, const Int &v) {
  393. if (v.sign == -1)
  394. stream << '-';
  395. stream << (v.a.empty() ? 0 : v.a.back());
  396. for (int i = (int) v.a.size() - 2; i >= 0; --i)
  397. stream << setw(base_digits) << setfill('0') << v.a[i];
  398. return stream;
  399. }
  400.  
  401. static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) {
  402. vector<long long> p(max(old_digits, new_digits) + 1);
  403. p[0] = 1;
  404. for (int i = 1; i < (int) p.size(); i++)
  405. p[i] = p[i - 1] * 10;
  406. vector<int> res;
  407. long long cur = 0;
  408. int cur_digits = 0;
  409. for (int i = 0; i < (int) a.size(); i++) {
  410. cur += a[i] * p[cur_digits];
  411. cur_digits += old_digits;
  412. while (cur_digits >= new_digits) {
  413. res.push_back(int(cur % p[new_digits]));
  414. cur /= p[new_digits];
  415. cur_digits -= new_digits;
  416. }
  417. }
  418. res.push_back((int) cur);
  419. while (!res.empty() && !res.back())
  420. res.pop_back();
  421. return res;
  422. }
  423.  
  424. typedef vector<long long> vll;
  425.  
  426. static vll karatsubaMultiply(const vll &a, const vll &b) {
  427. int n = a.size();
  428. vll res(n + n);
  429. if (n <= 32) {
  430. for (int i = 0; i < n; i++)
  431. for (int j = 0; j < n; j++)
  432. res[i + j] += a[i] * b[j];
  433. return res;
  434. }
  435.  
  436. int k = n >> 1;
  437. vll a1(a.begin(), a.begin() + k);
  438. vll a2(a.begin() + k, a.end());
  439. vll b1(b.begin(), b.begin() + k);
  440. vll b2(b.begin() + k, b.end());
  441.  
  442. vll a1b1 = karatsubaMultiply(a1, b1);
  443. vll a2b2 = karatsubaMultiply(a2, b2);
  444.  
  445. for (int i = 0; i < k; i++)
  446. a2[i] += a1[i];
  447. for (int i = 0; i < k; i++)
  448. b2[i] += b1[i];
  449.  
  450. vll r = karatsubaMultiply(a2, b2);
  451.  
  452. for (int i = 0; i < (int) a1b1.size(); i++)
  453. r[i] -= a1b1[i];
  454. for (int i = 0; i < (int) a2b2.size(); i++)
  455. r[i] -= a2b2[i];
  456.  
  457. for (int i = 0; i < (int) r.size(); i++)
  458. res[i + k] += r[i];
  459. for (int i = 0; i < (int) a1b1.size(); i++)
  460. res[i] += a1b1[i];
  461. for (int i = 0; i < (int) a2b2.size(); i++)
  462. res[i + n] += a2b2[i];
  463. return res;
  464. }
  465.  
  466. Int operator*(const Int &v) const {
  467. vector<int> a6 = convert_base(this->a, base_digits, 6);
  468. vector<int> b6 = convert_base(v.a, base_digits, 6);
  469.  
  470. vll a(a6.begin(), a6.end());
  471. vll b(b6.begin(), b6.end());
  472.  
  473. while (a.size() < b.size())
  474. a.push_back(0);
  475. while (b.size() < a.size())
  476. b.push_back(0);
  477. while (a.size() & (a.size() - 1))
  478. a.push_back(0), b.push_back(0);
  479.  
  480. vll c = karatsubaMultiply(a, b);
  481. Int res;
  482. res.sign = sign * v.sign;
  483. for (int i = 0, carry = 0; i < (int) c.size(); i++) {
  484. long long cur = c[i] + carry;
  485. res.a.push_back((int) (cur % 1000000));
  486. carry = (int) (cur / 1000000);
  487. }
  488. res.a = convert_base(res.a, 6, base_digits);
  489. res.trim();
  490. return res;
  491. }
  492.  
  493. //Added part.
  494.  
  495. friend Int max(const Int &a,const Int &b){
  496. if(a<b){
  497. return a;
  498. }
  499. return b;
  500. }
  501.  
  502. friend Int max(const Int &a,const int32_t &B){
  503. Int b = B;
  504. return max(a,b);
  505. }
  506.  
  507. friend Int max(const Int &a,const int64_t &B){
  508. Int b = B;
  509. return max(a,b);
  510. }
  511.  
  512. friend Int min(const Int &a,const Int &b){
  513. if(a>b){
  514. return b;
  515. }
  516. return a;
  517. }
  518.  
  519. friend Int min(const Int &a,const int32_t &B){
  520. Int b = B;
  521. return min(a,b);
  522. }
  523.  
  524. friend Int min(const Int &a,const int64_t &B){
  525. Int b = B;
  526. return min(a,b);
  527. }
  528.  
  529. friend Int pow(const Int &a,const Int &b){
  530. Int _c = 1;
  531. Int _b = b;
  532. Int _a = a;
  533. while(_b != 0){
  534. if(_b%2){
  535. _c *= _a;
  536. }
  537. _a *= _a;
  538. _b /= 2;
  539. }
  540. return _c;
  541. }
  542.  
  543. friend Int pow(const Int &a,const int32_t &B){
  544. Int b = B;
  545. return pow(a,b);
  546. }
  547.  
  548. friend Int pow(const Int &a,const int64_t &B){
  549. Int b = B;
  550. return pow(a,b);
  551. }
  552.  
  553. friend Int sqrt(Int a) {
  554. Int x0 = a, x1 = (a+1)/2;
  555. while (x1 < x0) {
  556. x0 = x1;
  557. x1 = (x1+a/x1)/2;
  558. }
  559. return x0;
  560. }
  561. };
  562.  
  563. vector<Int> pw(55);
  564. mt19937 rr(time(0));
  565.  
  566. Int count(int len, Int cur, int cur_len) {
  567. if(len == cur_len) {
  568. Int a = cur;
  569. // cerr << a << '\n';
  570. Int sum = a % 10;
  571. a /= 10;
  572. while(a > 0) {
  573. // if(sum == 0) cerr << "! " << '\n';
  574. if(cur % sum != 0) {
  575. return -1;
  576. }
  577. sum += a % 10;
  578. a /= 10;
  579. }
  580.  
  581. if(cur % sum != 0) {
  582. return -1;
  583. }
  584. return cur;
  585. }
  586.  
  587. vector<Int> kek(9);
  588. for(int i = 0; i < 9; i++) {
  589. kek[i] = i + 1;
  590. }
  591. shuffle(all(kek), rr);
  592. for(auto i : kek) {
  593. Int a = count(len, cur + i * pw[cur_len], cur_len + 1);
  594. if(a != -1) {
  595. return a;
  596. }
  597. }
  598. return -1;
  599. }
  600.  
  601. signed main() {
  602. seriy();
  603. pw[0] = 1;
  604. for(int i = 1; i <= 54; i++) {
  605. pw[i] = pw[i - 1] * 10ll;
  606. }
  607. vector<__int128> a = {1, 48, 324, 8448, 54648, 182688, 8194284, 87521616, 786699648, 3632652144, 92829528792, 285675714324, 5588151343236, 35772121112112, 361482121112112, 8118231121112112, 39966432121112112, 352442211121112112, 2865953211121112112, -1, 973297415211121112112};
  608. // int b;
  609. // cin >> b;
  610. // if(b >= 20) {
  611. // vector<string> heh = {"97485678411121112112", "973297415211121112112", "4578699215211121112112", "78426373115211121112112"};
  612. // cout << heh[b - 20];
  613. // }
  614. // else {
  615. // cout << a[b - 1];
  616. // }
  617. int CNT = 24;
  618. vector<Int> ans(56);
  619. Int start = 121111211121112112;
  620. while(CNT <= 54) {
  621. ans[CNT] = count(CNT, start, 18);
  622. cerr << CNT << " " << "\"" << ans[CNT] << "\", ";
  623. CNT++;
  624. }
  625. return 0;
  626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement