A
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL n;
signed main() {
// freopen("in", "r", stdin);
while (cin >> n) {
LL tmp = (LL)sqrt(n);
LL x = tmp * tmp, y = (tmp + 1) * (tmp + 1);
if (abs(x - n) > abs(y - n)) cout << y << endl;
else cout << x << endl;
}
return 0;
}
B
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
inline bool scan_d(int &num) {
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
const int maxn = 1000100;
int n, q;
int a[maxn];
int vis[1 << 22];
signed main() {
// freopen("in", "r", stdin);
memset(vis, 0, sizeof vis);
scan_d(n); scan_d(q);
for (int i = 1; i <= n; i++) {
scan_d(a[i]);
vis[a[i]]++;
}
while (q--) {
int k, x, y;
scan_d(k); scan_d(x); scan_d(y);
if ((a[x] ^ a[y]) == k) {
printf("%d\n", 1);
continue;
}
if (vis[a[x] ^ k] && vis[a[y] ^ k]) {
if ((a[x] ^ k) == (a[y] ^ k)) printf("%d\n", 2);
else printf("%d\n", -1);
continue;
}
printf("-1\n");
}
return 0;
}
C
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
inline bool scan_d(LL &num) {
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
const int maxn = 1001000;
LL n;
LL a[maxn], tot[maxn];
signed main() {
// freopen("in", "r", stdin);
scan_d(n);
LL ret = 0;
for (int i = 1; i <= n; i++) {
scan_d(a[i]);
tot[i] = abs(a[i] - a[i - 1]);
}
LL x = INT_MAX, y = INT_MAX;
for (int i = 2; i <= n; i++) {
if (y == INT_MAX) y = tot[i];
else y = __gcd(y, tot[i]);
}
x = (y - (a[1] % y)) % y;
printf("%lld %lld\n", y, x);
return 0;
}