fork download
  1. /**
  2.  * author: orzvanh14
  3.  * created: 23.12.2022 10:08:02
  4.  * too lazy to update time
  5. **/
  6. // i wants to take ioi
  7. //binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. #define int long long
  13. #define nn "\n"
  14. #define pi pair<int, int>
  15. #define fi first
  16. #define se second
  17. #define lb lower_bound
  18. #define ub upper_bound
  19. #define eb emplace_back
  20. #define pb push_back
  21. #define TASK " "
  22.  
  23. #define ms(a, x) memset(a, x, sizeof(a))
  24. #define all(a) a.begin(), a.end()
  25. #define All(a, n) a + 1, a + 1 + n
  26.  
  27. #define LOG 19
  28.  
  29.  
  30. const int INF = 1e18;
  31. const int mod = 1e9+7;
  32. const int N = 1e6 + 5;
  33. const int maxN = 1e5 + 5;
  34. int MOD = 998244353;
  35. int bit[200000];
  36. struct node{
  37. int kc, u, hk;
  38. bool operator<(const node& other) const {
  39. return kc > other.kc;
  40. }
  41. };
  42. struct edge{
  43. int u, v, w, id;
  44. friend bool operator < ( edge a, edge b){
  45. return a.w > b.w;
  46. }
  47. };
  48. string s;
  49. int a[N];
  50. void nhap(){
  51. cin >> s;
  52.  
  53. }
  54. void solve(){
  55. for(int i = 1; i < s.size(); i++){
  56. int j = a[i - 1];
  57. while(j > 0 && s[i] != s[j]){
  58. j = a[j - 1];
  59. }
  60. if(s[i] == s[j]){
  61. j++;
  62. }
  63. a[i] = j;
  64. }
  65. int sz = s.size() - a[s.size() - 1];
  66. int k = 1;
  67. string t = s;
  68. if(s.size() % sz == 0){
  69. k = s.size() / sz;
  70. t = s.substr(0, sz);
  71. }
  72.  
  73. cout << k << t << nn;
  74. }
  75. signed main() {
  76. // freopen("piggyback.in", "r", stdin);
  77. // freopen("piggyback.out", "w", stdout);
  78. ios_base::sync_with_stdio(0);
  79. cin.tie(0);
  80. cout.tie(0);
  81. nhap();
  82. solve();
  83. return 0;
  84.  
  85. }
  86.  
Success #stdin #stdout 0.01s 5664KB
stdin
aaaaa
stdout
5a