Class
$A_i = a \cdot i \% n$
有 $A_i = k \cdot gcd(a, n)$
证明:
$A_0 = 0, A_x = x \cdot a - y \cdot n$
$令 d = gcd(a, n)$
$A_x \% d = (x \cdot a \% d - y \cdot n \% d) \% d = 0$ 得证
循环节为$\frac {n}{gcd(a, n)}$
Replay
Dup4:
- 自闭了,啥都不会,想开一道无人做的字符串,喵喵喵?
- 总是陷入思维的泥浆,爬不出来,T那么大,怎么就想不到预处理呢
X:
- 成功晋升码农
- 第三次忘记预处理是个啥,最后全靠队友一波rush
- 日常开局血崩,这口锅必须要背
Solution
A: Erase Numbers II
思路:
$n^2 暴力 注意最大的那项会爆 long\; long 但不会爆 unsigned \;long \;long$
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 5 typedef unsigned long long ull; 6 const int maxn = 1e5 + 10; 7 8 int n; 9 ull arr[maxn]; 10 ull len[maxn]; 11 12 int main() 13 { 14 int t; 15 scanf("%d", &t); 16 for(int cas = 1; cas <= t; ++cas) 17 { 18 printf("Case #%d: ", cas); 19 scanf("%d", &n); 20 for(int i = 1; i <= n; ++i) 21 { 22 scanf("%llu", arr + i); 23 len[i] = 1; 24 ull x = arr[i]; 25 while(x) 26 { 27 len[i] *= 10; 28 x /= 10; 29 } 30 } 31 ull ans = 0; 32 for(int i = 1; i <= n; ++i) 33 { 34 for(int j = i + 1; j <= n; ++j) 35 { 36 ans = max(ans, arr[i] * len[j] + arr[j]); 37 } 38 } 39 printf("%llu\n", ans); 40 } 41 return 0; 42 }