A小红平分糖果
Code:
#include<bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << x << '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; if (n & 1) cout << -1; else cout << n / 2 << ' ' << n / 2; return 0; }
B小红的完全平方数
#include<bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << ": " << x << '\n'; typedef long long i64; bool check (i64 x) { i64 sq = sqrt(x); return sq * sq == x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); i64 x, pre = 0, suf = 0; cin >> x; for (i64 i = x; ; i += 2) { if (check(i)) break; pre++; } for (i64 i = x; ; i -= 2) { if (check(i)) break; suf ++; } cout << min(suf, pre) << '\n'; return 0; }
标签:周赛,cout,namespace,43,i64,牛客,include,check From: https://www.cnblogs.com/youhualiuh/p/18200754