1. 程式人生 > >CodeForces Codeforces Round #547 (Div. 3) 2019年3月20日 (補題)

CodeForces Codeforces Round #547 (Div. 3) 2019年3月20日 (補題)

img inf == stream code pan col using 分享圖片

A.

技術分享圖片

Examples

Input

120 51840
Output

7
Input

42 42

Output

0
Input

48 72

Output

-1

#include <iostream>

using namespace std;

int main()
{
	int m, n;
	cin >> m >> n;
	int step = 0;
	if (n % m != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	else
	{
		int k = n / m;
		while (k % 2 == 0) {
			k /= 2;
			step++;
		}
		while (k % 3 == 0) {
			k /= 3;
			step++;
		}
		if (k != 1) {
			cout << -1 << endl;
		}
			
		else
		{
			cout << step << endl;
		}
	}
}

B.

技術分享圖片

Examples

Input

5
1 0 1 0 1
Output

2
Input

6
0 1 0 1 1 0

Output

2
Input

7
1 0 1 1 1 0 1

Output

3
Input

3
0 0 0

Output

0

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a[200001];
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int s = 0;
	int max1 = 0;
	if (a[0] == 0) {
		
		for (int i = 1; i < n; i++) {
			if (a[i] == 1) {		
				++s;
				max1 = max(s, max1);
				continue;
			}
			max1 = max(s, max1);
			s = 0;
		}
		cout << max1 << endl;
	}
	if (a[0] == 1) {
		if (a[n - 1] == 0) {
			for (int i = 0; i < n; i++) {
				if (a[i] == 1) {
					++s;
					max1 = max(s, max1);
					continue;
				}
				max1 = max(s, max1);
				s = 0;
			}
			cout << max1 << endl;
		}
		else {
			int aa = 0;
			for (int i = n - 1; a[i] == 1 && i >= 0; i--) {
				s++;
				aa = i;
			}
			for (int i = 0; i < aa; i++) {
				if (a[i] == 1) {
					++s;
					max1 = max(s, max1);
					continue;
				}
				max1 = max(s, max1);
				s = 0;
			}
			cout << max1 << endl;
		}
	}


}


CodeForces Codeforces Round #547 (Div. 3) 2019年3月20日 (補題)