Advertisement
Korotkodul

имто excel code

Feb 15th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. //#include <bits/stdc++.h>
  11. #define pii pair <int,int>
  12. using namespace std;
  13. using ll = long long;
  14. using ld = double;
  15. void cv(vector <int> &v){
  16.     for (auto x: v) cout<<x<<' ';
  17.     cout<<"\n\n";
  18. }
  19. int gcd(int a, int b) {
  20.     if (a < b) {
  21.         swap(a, b);
  22.     }
  23.  
  24.     while (b) {
  25.         a %= b;
  26.         swap(a, b);
  27.     }
  28.  
  29.     return a;
  30. }
  31.  
  32. int lcm(int a, int b) {
  33.     return a / gcd(a, b) * b;   //используя форму a * b / gcd(a, b),
  34. }
  35.  
  36. struct nmb{
  37.     int a,b;
  38.     nmb pls(nmb x){
  39.         int c,d;
  40.         c = lcm(b, x.b);
  41.         d = a * (c / b) + x.a * (c / x.b);
  42.         nmb r = {d, c};
  43.         return r;
  44.     }
  45. };
  46.  
  47. map <char, int> L;
  48.  
  49. int nm(string x){
  50.     reverse(x.begin(), x.end());
  51.     int sz = x.size();
  52.     int res = 0;
  53.     for (int i=0;i<sz;++i){
  54.         res += pow(26, i) * L[x[i]];
  55.     }
  56.     return res;
  57. }
  58. vector <vector <nmb> > tb(1130, vector <nmb> (50));
  59.  
  60. bool chk(nmb x){
  61.     bool r = 0;
  62.     if (x.a == 0) return 1;
  63.     if (x.a < x.b) return 0;
  64.     int dv = x.a / x.b;
  65.     if (x.b * dv == x.a) r = 1;
  66.     return r;
  67. }
  68. int main()
  69. {
  70.     int cnt = 1;
  71.     for (int i = 65; i <= 90;++i){
  72.         char l = i;
  73.         //cout<<"l= "<<l<<' '<<cnt<<'\n';
  74.         L[l] = cnt;
  75.         cnt++;
  76.     }
  77.     //for (auto x: L)cout<<x.first<<' '<<x.second<<'\n';
  78.     tb[1][nm("A")] = {5,1};
  79.     tb[1][nm("B")] = {4,1};
  80.     tb[1][nm("C")] = {3,1};
  81.     tb[1][nm("E")] = {15,1};
  82.     nmb add = {15,-1};
  83.     for (int i = 2; i <= 1024; ++i){
  84.         add.b = 25;
  85.         tb[i][nm("A")] = tb[i-1][nm("A")].pls(add);
  86.          //cout<< tb[i][nm("A")]<<"\n";
  87.     }
  88.     for (int i = 2; i <=1024;++i){
  89.         add.b = 4;
  90.         tb[i][nm("B")] = tb[i-1][nm("B")].pls(add);
  91.         //cout<< tb[i][nm("B")]<<"\n";
  92.  
  93.     }
  94.     for (int i = 2; i <= 1024; ++i){
  95.         add.b = 40;
  96.         tb[i][nm("C")] = tb[i-1][nm("C")].pls(add);
  97.     }
  98.     int ans=0;
  99.     vector <nmb> S(1030);
  100.     string f = "               ";
  101.     for (int i=2;i<=1024;++i){
  102.         S[i] = tb[i][nm("A")].pls(tb[i][nm("B")]).pls(tb[i][nm("C")]);
  103.         if (chk(S[i])) ans++;
  104.     }
  105.     cout<<ans<<"\n";
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement