Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- //#include <bits/stdc++.h>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n\n";
- }
- int gcd(int a, int b) {
- if (a < b) {
- swap(a, b);
- }
- while (b) {
- a %= b;
- swap(a, b);
- }
- return a;
- }
- int lcm(int a, int b) {
- return a / gcd(a, b) * b; //используя форму a * b / gcd(a, b),
- }
- struct nmb{
- int a,b;
- nmb pls(nmb x){
- int c,d;
- c = lcm(b, x.b);
- d = a * (c / b) + x.a * (c / x.b);
- nmb r = {d, c};
- return r;
- }
- };
- map <char, int> L;
- int nm(string x){
- reverse(x.begin(), x.end());
- int sz = x.size();
- int res = 0;
- for (int i=0;i<sz;++i){
- res += pow(26, i) * L[x[i]];
- }
- return res;
- }
- vector <vector <nmb> > tb(1130, vector <nmb> (50));
- bool chk(nmb x){
- bool r = 0;
- if (x.a == 0) return 1;
- if (x.a < x.b) return 0;
- int dv = x.a / x.b;
- if (x.b * dv == x.a) r = 1;
- return r;
- }
- int main()
- {
- int cnt = 1;
- for (int i = 65; i <= 90;++i){
- char l = i;
- //cout<<"l= "<<l<<' '<<cnt<<'\n';
- L[l] = cnt;
- cnt++;
- }
- //for (auto x: L)cout<<x.first<<' '<<x.second<<'\n';
- tb[1][nm("A")] = {5,1};
- tb[1][nm("B")] = {4,1};
- tb[1][nm("C")] = {3,1};
- tb[1][nm("E")] = {15,1};
- nmb add = {15,-1};
- for (int i = 2; i <= 1024; ++i){
- add.b = 25;
- tb[i][nm("A")] = tb[i-1][nm("A")].pls(add);
- //cout<< tb[i][nm("A")]<<"\n";
- }
- for (int i = 2; i <=1024;++i){
- add.b = 4;
- tb[i][nm("B")] = tb[i-1][nm("B")].pls(add);
- //cout<< tb[i][nm("B")]<<"\n";
- }
- for (int i = 2; i <= 1024; ++i){
- add.b = 40;
- tb[i][nm("C")] = tb[i-1][nm("C")].pls(add);
- }
- int ans=0;
- vector <nmb> S(1030);
- string f = " ";
- for (int i=2;i<=1024;++i){
- S[i] = tb[i][nm("A")].pls(tb[i][nm("B")]).pls(tb[i][nm("C")]);
- if (chk(S[i])) ans++;
- }
- cout<<ans<<"\n";
- }
Add Comment
Please, Sign In to add comment