完善程序一代码:
#include <iostream>
using namespace std;
const int N = 110000, P = 10007;
int n;
int a[N], len;
int ans;
void getDivisor() {
len = 0;
for (int i = 1; i * i <= n; ++i)
if (n % i == 0) {
a[++len] = i;
if (n / i != i) a[++len] = n / i;
}
}
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
cin >> n;
getDivisor();
ans = 0;
for (int i = 1; i <= len; ++i) {
for (int j = i + 1; j <= len; ++j) {
ans = (ans + gcd(a[i], a[j])) % P;
}
}
cout << ans << endl;
return 0;
}
完善程序二代码:
#include <iostream>
using namespace std;
const int N = 100010;
int n;
int L[N], R[N], a[N];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
a[x] = i;
}
for (int i = 1; i <= n; ++i) {
R[i] = i + 1;
L[i] = i - 1;
}
for (int i = 1; i <= n; ++i) {
L[R[a[i]]] = L[a[i]];
R[L[a[i]]] = R[a[i]];
}
for (int i = 1; i <= n; ++i) {
cout << R[i] << " ";
}
cout<<endl;
return 0;
}