fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <string>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <set>
  9. #include <map>
  10. #include <cmath>
  11. #include <ctime>
  12. using namespace std;
  13.  
  14. #ifdef LOCAL
  15. #define eprintf(...) fprintf(stderr, __VA_ARGS__)
  16. #else
  17. #define eprintf(...) 42
  18. #endif
  19.  
  20. typedef long long ll;
  21. const int N = (int)1e5 + 10;
  22. const ll INF = (ll)1e18;
  23. const int LOG = 17;
  24. ll MaxValue, Border;
  25. ll a[N];
  26. ll sparse[LOG][N];
  27. int h[N];
  28. int n;
  29.  
  30. ll gcd(ll x, ll y)
  31. {
  32. return y == 0 ? x : gcd(y, x % y);
  33. }
  34.  
  35. ll cheatGcd(ll x, ll y)
  36. {
  37. if (y <= Border)
  38. return 1;
  39. return y == 0 ? x : gcd(y, x % y);
  40. }
  41.  
  42. void read()
  43. {
  44. scanf("%d", &n);
  45. for (int i = 0; i < n; i++)
  46. scanf("%lld", &a[i]);
  47. }
  48.  
  49. void calcSparse()
  50. {
  51. for (int i = 0; i < LOG; i++)
  52. {
  53. for (int s = 0; s <= n - (1 << i); s++)
  54. {
  55. if (i == 0)
  56. sparse[i][s] = a[s];
  57. else
  58. sparse[i][s] = gcd(sparse[i - 1][s], sparse[i - 1][s + (1 << (i - 1))]);
  59. }
  60. }
  61. }
  62.  
  63. ll getCheatGcd(int l, int r)
  64. {
  65. int t = h[r - l + 1];
  66. return cheatGcd(sparse[t][l], sparse[t][r - (1 << t) + 1]);
  67. }
  68.  
  69. void calcH()
  70. {
  71. h[1] = 0;
  72. for (int i = 2; i < N; i++)
  73. h[i] = h[i / 2] + 1;
  74. }
  75.  
  76. void solve()
  77. {
  78. MaxValue = -INF;
  79. for (int i = 0; i < n; i++)
  80. MaxValue = max(MaxValue, a[i]);
  81. Border = MaxValue / (n + 1);
  82.  
  83. calcSparse();
  84. calcH();
  85. ll ans = MaxValue;
  86. for (int i = 0; i < n; i++)
  87. {
  88. int t = i;
  89. while (t < n)
  90. {
  91. ll curGcd = getCheatGcd(i, t);
  92. int l = t, r = n;
  93. while (r - l > 1)
  94. {
  95. int mid = (l + r) / 2;
  96. if (getCheatGcd(i, mid) != curGcd)
  97. r = mid;
  98. else
  99. l = mid;
  100. }
  101. ans = max(ans, curGcd * (r - i));
  102. if (curGcd == 1)
  103. break;
  104. t = r;
  105. }
  106. }
  107. printf("%lld\n", ans);
  108. }
  109.  
  110. int main()
  111. {
  112. #ifdef LOCAL
  113. freopen ("input.txt", "r", stdin);
  114. freopen ("output.txt", "w", stdout);
  115. #endif
  116. int T;
  117. scanf("%d", &T);
  118. for (int i = 0; i < T; i++)
  119. {
  120. read();
  121. solve();
  122. }
  123. return 0;
  124. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <iostream>
^
Main.java:1: error: class, interface, or enum expected
#include <iostream>
         ^
Main.java:2: error: illegal character: '#'
#include <cstdio>
^
Main.java:3: error: illegal character: '#'
#include <cstdlib>
^
Main.java:4: error: illegal character: '#'
#include <cstring>
^
Main.java:5: error: illegal character: '#'
#include <string>
^
Main.java:6: error: illegal character: '#'
#include <vector>
^
Main.java:7: error: illegal character: '#'
#include <algorithm>
^
Main.java:8: error: illegal character: '#'
#include <set>
^
Main.java:9: error: illegal character: '#'
#include <map>
^
Main.java:10: error: illegal character: '#'
#include <cmath>
^
Main.java:11: error: illegal character: '#'
#include <ctime>
^
Main.java:14: error: illegal character: '#'
#ifdef LOCAL
^
Main.java:15: error: illegal character: '#'
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
	^
Main.java:16: error: illegal character: '#'
#else
^
Main.java:17: error: illegal character: '#'
	#define eprintf(...) 42
	^
Main.java:18: error: illegal character: '#'
#endif
^
Main.java:21: error: class, interface, or enum expected
const int N = (int)1e5 + 10;
^
Main.java:22: error: class, interface, or enum expected
const ll INF = (ll)1e18;
^
Main.java:23: error: class, interface, or enum expected
const int LOG = 17;
^
Main.java:24: error: class, interface, or enum expected
ll MaxValue, Border;
^
Main.java:25: error: class, interface, or enum expected
ll a[N];
^
Main.java:26: error: class, interface, or enum expected
ll sparse[LOG][N];
^
Main.java:27: error: class, interface, or enum expected
int h[N];
^
Main.java:28: error: class, interface, or enum expected
int n;
^
Main.java:30: error: class, interface, or enum expected
ll gcd(ll x, ll y)
^
Main.java:33: error: class, interface, or enum expected
}
^
Main.java:39: error: class, interface, or enum expected
	return y == 0 ? x : gcd(y, x % y);
	^
Main.java:40: error: class, interface, or enum expected
}
^
Main.java:45: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	^
Main.java:45: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	                ^
Main.java:45: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	                       ^
Main.java:47: error: class, interface, or enum expected
}
^
Main.java:51: error: class, interface, or enum expected
	for (int i = 0; i < LOG; i++)
	                ^
Main.java:51: error: class, interface, or enum expected
	for (int i = 0; i < LOG; i++)
	                         ^
Main.java:53: error: class, interface, or enum expected
		for (int s = 0; s <= n - (1 << i); s++)
		                ^
Main.java:53: error: class, interface, or enum expected
		for (int s = 0; s <= n - (1 << i); s++)
		                                   ^
Main.java:57: error: class, interface, or enum expected
			else
			^
Main.java:59: error: class, interface, or enum expected
		}
		^
Main.java:66: error: class, interface, or enum expected
	return cheatGcd(sparse[t][l], sparse[t][r - (1 << t) + 1]);
	^
Main.java:67: error: class, interface, or enum expected
}
^
Main.java:72: error: class, interface, or enum expected
	for (int i = 2; i < N; i++)
	^
Main.java:72: error: class, interface, or enum expected
	for (int i = 2; i < N; i++)
	                ^
Main.java:72: error: class, interface, or enum expected
	for (int i = 2; i < N; i++)
	                       ^
Main.java:74: error: class, interface, or enum expected
}
^
Main.java:79: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	^
Main.java:79: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	                ^
Main.java:79: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	                       ^
Main.java:81: error: class, interface, or enum expected
	Border = MaxValue / (n + 1);
	^
Main.java:83: error: class, interface, or enum expected
	calcSparse();
	^
Main.java:84: error: class, interface, or enum expected
	calcH();
	^
Main.java:85: error: class, interface, or enum expected
	ll ans = MaxValue;
	^
Main.java:86: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	^
Main.java:86: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	                ^
Main.java:86: error: class, interface, or enum expected
	for (int i = 0; i < n; i++)
	                       ^
Main.java:89: error: class, interface, or enum expected
		while (t < n)
		^
Main.java:92: error: class, interface, or enum expected
			int l = t, r = n;
			^
Main.java:93: error: class, interface, or enum expected
			while (r - l > 1)
			^
Main.java:96: error: class, interface, or enum expected
				if (getCheatGcd(i, mid) != curGcd)
				^
Main.java:98: error: class, interface, or enum expected
				else
				^
Main.java:100: error: class, interface, or enum expected
			}
			^
Main.java:102: error: class, interface, or enum expected
			if (curGcd == 1)
			^
Main.java:104: error: class, interface, or enum expected
			t = r;
			^
Main.java:105: error: class, interface, or enum expected
		}
		^
Main.java:108: error: class, interface, or enum expected
}
^
Main.java:112: error: illegal character: '#'
#ifdef LOCAL
^
Main.java:114: error: class, interface, or enum expected
	freopen ("output.txt", "w", stdout);
	^
Main.java:115: error: illegal character: '#'
#endif
^
Main.java:116: error: class, interface, or enum expected
	int T;
	^
Main.java:117: error: class, interface, or enum expected
	scanf("%d", &T);
	^
Main.java:118: error: class, interface, or enum expected
	for (int i = 0; i < T; i++)
	^
Main.java:118: error: class, interface, or enum expected
	for (int i = 0; i < T; i++)
	                ^
Main.java:118: error: class, interface, or enum expected
	for (int i = 0; i < T; i++)
	                       ^
Main.java:121: error: class, interface, or enum expected
		solve();
		^
Main.java:122: error: class, interface, or enum expected
	}
	^
Main.java:124: error: class, interface, or enum expected
}
^
76 errors
stdout
Standard output is empty