Advertisement
mickypinata

TOI13: Timer Switch

Nov 20th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6.     int n;
  7.     scanf("%d", &n);
  8.     string s = "";
  9.     cin >> s;
  10.  
  11.     vector<int> component;
  12.     double t = sqrt(n);
  13.     for(int i = 1; i <= t; ++i){
  14.         if(n % i == 0){
  15.             component.push_back(i);
  16.             component.push_back(n / i);
  17.         }
  18.     }
  19.     sort(component.begin(), component.end());
  20.  
  21.     for(auto x : component){
  22.         string news = s;
  23.         news += news.substr(0, x);
  24.         news = news.substr(x, n + x);
  25.         if(news == s){
  26.             cout << x;
  27.             break;
  28.         }
  29.     }
  30.  
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement