Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- short c[10002];
- int P2 (long long &x)
- {
- int t = 0;
- while(x % 2 == 0)
- {
- x = x / 2;
- ++t;
- }
- return t;
- }
- int main()
- {
- ifstream fin ("memory006.in");
- ofstream fout("memory006.out");
- int n, k, t = 0, pf = 0, sum = 0, s = 0, pi = 1;
- fin >> n >> k;
- long long x;
- for (int i = 1; i <= n; i++)
- {
- fin >> x;
- t = P2(x);
- if (x == 1) // putere a lui 2
- {
- pf = (pf + 1) % 10001;
- c[pf] = t;
- sum = sum + t;
- if (sum == k)
- s++;
- if (sum > k)
- {
- while(sum > k)
- {
- sum = sum - c[pi];
- pi = (pi + 1) % 10001;
- }
- if(sum == k)
- s++;
- }
- }
- else
- {
- pf = sum = 0;
- pi = 1;
- }
- }
- fout << s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement