Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <stdio.h>
- using namespace std;
- bool search(int k, int j, vector<int> m, int n) {
- int temp = m[j];
- for (int i = j + k; i < n - 1; i+= k) {
- if (temp != m[i]) {
- return false;
- }
- }
- return true;
- }
- int main() {
- //std::ifstream fin("input.txt");
- //std::ofstream fout("output.txt");
- int n;
- cin >> n;
- vector<int> m(n);
- bool f = true;
- scanf_s("%d", &m[0]);
- for (int i = 1; i < n; i++) {
- scanf_s("%d", &m[i]);
- if (m[0] != m[i] && f) {
- f = !f;
- }
- }
- if (f) {
- printf("%d", 1);
- return 0;
- }
- for (int i = 2; i <= (n - 1) / 2; i++) {
- bool f = true;
- if (m[0] == m[i] && (n-1) % i == 0) {
- for (int j = 0; j <= i && f; j++) {
- f = search(i, j, m, n);
- }
- }
- else {
- f = !f;
- }
- if (f) {
- printf("%d", i);
- return 0;
- }
- }
- printf("%d", n - 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment