Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int q;
- long long n;
- int countSub(string str)
- {
- int MAX_CHAR = 256;
- vector<int> last(MAX_CHAR, -1);
- int n = str.length();
- int dp[n+1];
- dp[0] = 1;
- for (int i=1; i<=n; i++)
- {
- dp[i] = 2*dp[i-1];
- if (last[str[i-1]] != -1)dp[i] = dp[i] - dp[last[str[i-1]]];
- last[str[i-1]] = (i-1);
- }
- return dp[n];
- }
- long long NWD (long long a, long long b)
- {
- if (a == 0) return b;
- return NWD(b%a, a);
- }
- void NWD_Create (long long n)
- {
- long long a = (n+1)/1.61803398875;
- long long b = n+1-a;
- while (a > 0 && b > 0)
- {
- while (NWD(a,b) != 1) a++, b--;
- if (a > b)
- {
- cout << 'a';
- a -= b;
- }
- else
- {
- cout << 'b';
- b -= a;
- }
- }
- }
- int main()
- {
- NWD_Create(8);
- cout << "\n" << " " << countSub("ababababbaabb");
- // ios_base::sync_with_stdio(0);
- // cin.tie(0);
- // cout.tie(0);
- cin >> q;
- while (q--)
- {
- cin >> n;
- NWD_Create(n);
- cout << "\n";
- }
- return 0;
- }
- /*
- 2
- 14
- 4
- ---
- 5
- 7
- 10
- 42
- 15
- 512
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement