problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")" << endl
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long> vl;
typedef vector<vector<long>> vvl;
typedef vector<string> vs;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << ",";
}
os << "]";
return os;
}
template <typename T> T input() {
T t;
cin >> t;
return t;
}
template <typename T> vector<T> input(const int N) {
vector<T> v(N);
repeat(i, N) cin >> v[i];
return v;
}
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long mul(const long long &a, const long long &b, const long long &mod) {
return ((a % mod) * (b % mod)) % mod;
}
long long power(const long long &x, const long long &y, const long long &mod) {
if (y == 0) {
return 1;
} else if (y == 1) {
return x % mod;
} else {
long long value = power(x, y / 2, mod);
if (y % 2 == 0) {
return mul(value, value, mod);
} else {
return mul(value, value, mod) * x % mod;
}
}
}
long long div(const long long &a, const long long &b, const long long &mod) {
return mul(a, power(b, mod - 2, mod), mod);
}
map<long long, long long> factorials;
long long factorial(const long long &n, const long long &mod) {
if (n == 0 || n == 1) {
return 1;
}
if (factorials[n] != 0) {
return factorials[n];
}
factorials[n] = n * factorial(n - 1, mod) % mod;
return factorials[n] % mod;
}
long long combination(const long long &n, const long long &x,
const long long &mod) {
long long numerator = 1;
long long denominator = 1;
repeat(i, x) {
numerator *= (n - i) % mod;
numerator %= mod;
denominator *= (i + 1) % mod;
denominator %= mod;
}
return div(numerator, denominator, mod);
}
int main() {
long long N = 0;
cin >> N;
long long count = 0;
long long last = sqrt(N);
for (long long m = 1; m <= last; ++m) {
auto ans = lldiv(N, m);
if (ans.rem == 0) {
if (m == ans.quot) {
auto check = lldiv(N, m - 1);
if (check.quot == check.rem) {
count += (m - 1);
}
} else {
if (m - 1 != 0) {
auto check1 = lldiv(N, m - 1);
if (check1.quot == check1.rem) {
count += (m - 1);
}
}
if (ans.quot - 1 != 0) {
auto check2 = lldiv(N, ans.quot - 1);
if (check2.quot == check2.rem) {
count += (ans.quot - 1);
}
}
}
}
}
cout << count << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")" << endl
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long> vl;
typedef vector<vector<long>> vvl;
typedef vector<string> vs;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << ",";
}
os << "]";
return os;
}
template <typename T> T input() {
T t;
cin >> t;
return t;
}
template <typename T> vector<T> input(const int N) {
vector<T> v(N);
repeat(i, N) cin >> v[i];
return v;
}
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long mul(const long long &a, const long long &b, const long long &mod) {
return ((a % mod) * (b % mod)) % mod;
}
long long power(const long long &x, const long long &y, const long long &mod) {
if (y == 0) {
return 1;
} else if (y == 1) {
return x % mod;
} else {
long long value = power(x, y / 2, mod);
if (y % 2 == 0) {
return mul(value, value, mod);
} else {
return mul(value, value, mod) * x % mod;
}
}
}
long long div(const long long &a, const long long &b, const long long &mod) {
return mul(a, power(b, mod - 2, mod), mod);
}
map<long long, long long> factorials;
long long factorial(const long long &n, const long long &mod) {
if (n == 0 || n == 1) {
return 1;
}
if (factorials[n] != 0) {
return factorials[n];
}
factorials[n] = n * factorial(n - 1, mod) % mod;
return factorials[n] % mod;
}
long long combination(const long long &n, const long long &x,
const long long &mod) {
long long numerator = 1;
long long denominator = 1;
repeat(i, x) {
numerator *= (n - i) % mod;
numerator %= mod;
denominator *= (i + 1) % mod;
denominator %= mod;
}
return div(numerator, denominator, mod);
}
int main() {
long long N = 0;
cin >> N;
long long count = 0;
long long last = sqrt(N);
for (long long m = 1; m <= last; ++m) {
auto ans = lldiv(N, m);
if (ans.rem == 0) {
if (m == ans.quot) {
if (m - 1 != 0) {
auto check = lldiv(N, m - 1);
if (check.quot == check.rem) {
count += (m - 1);
}
}
} else {
if (m - 1 != 0) {
auto check1 = lldiv(N, m - 1);
if (check1.quot == check1.rem) {
count += (m - 1);
}
}
if (ans.quot - 1 != 0) {
auto check2 = lldiv(N, ans.quot - 1);
if (check2.quot == check2.rem) {
count += (ans.quot - 1);
}
}
}
}
}
cout << count << endl;
return 0;
}
| replace | 126 | 129 | 126 | 131 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n) \
for (int vari = 0; vari < (n)-1; ++vari) \
for (int varj = vari + 1; varj < (n); ++varj)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair
#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T, vector<T>, greater<T>>
template <class T> inline void amin(T &a, T const &b) { a = min(a, b); }
template <class T> inline void amax(T &a, T const &b) { a = max(a, b); }
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
while (a)
swap(a, b %= a);
return b;
}
template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; }
const ll MOD = 1000000007LL;
ll ADD(ll x, ll y) { return (x + y) % MOD; }
ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; }
ll MUL(ll x, ll y) { return x * y % MOD; }
ll POW(ll x, ll e) {
ll v = 1;
for (; e; x = MUL(x, x), e >>= 1)
if (e & 1)
v = MUL(v, x);
return v;
}
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/
return MUL(x, POW(y, MOD - 2));
}
ll solve(ll N) {
ll ans = 0;
for (ll x = 1;; ++x) {
if (N % x)
continue;
ll m = N / x - 1;
if (x >= m) {
break;
}
ans += m;
}
return ans;
}
int main() {
ll N;
cin >> N;
cout << solve(N) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define NDEBUG
#include <cassert>
typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<double, double> dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define FOR(var, from, to) for (int var = (from); var <= (to); ++var)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define rep1(var, n) for (int var = 1; var <= (n); ++var)
#define repC2(vari, varj, n) \
for (int vari = 0; vari < (n)-1; ++vari) \
for (int varj = vari + 1; varj < (n); ++varj)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define found(s, e) ((s).find(e) != (s).end())
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define mid(x, y) ((x) + ((y) - (x)) / 2)
#define IN(x, a, b) ((a) <= (x) && (x) <= (b))
#define cons make_pair
#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T, vector<T>, greater<T>>
template <class T> inline void amin(T &a, T const &b) { a = min(a, b); }
template <class T> inline void amax(T &a, T const &b) { a = max(a, b); }
inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) {
while (a)
swap(a, b %= a);
return b;
}
template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; }
const ll MOD = 1000000007LL;
ll ADD(ll x, ll y) { return (x + y) % MOD; }
ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; }
ll MUL(ll x, ll y) { return x * y % MOD; }
ll POW(ll x, ll e) {
ll v = 1;
for (; e; x = MUL(x, x), e >>= 1)
if (e & 1)
v = MUL(v, x);
return v;
}
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/
return MUL(x, POW(y, MOD - 2));
}
ll solve(ll N) {
ll ans = 0;
ll sq = sqrt(N);
for (ll x = 1; x <= sq + 3; ++x) {
if (N % x)
continue;
ll m = N / x - 1;
if (x >= m) {
break;
}
ans += m;
}
return ans;
}
int main() {
ll N;
cin >> N;
cout << solve(N) << endl;
return 0;
}
| replace | 72 | 73 | 72 | 74 | TLE | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
// int X[100000], Y[100000];
//
// void solve() {
// int P, Q, x, y;
// char d;
// cin>>P>>Q;
// memset(X, 0, sizeof(X));
// memset(Y, 0, sizeof(Y));
// for (int i=0; i<P; i++) {
// cin>>x>>y>>d;
// if (d == 'N') for (int j= y+1; j<=Q; j++) Y[j]++;
// if (d == 'S') for (int j= 0; j<y; j++) Y[j]++;
// if (d == 'E') for (int j= x+1; x<=Q; j++) X[j]++;
// if (d == 'W') for (int j= 0; j<x; j++) X[j]++;
// }
// int ans = 0;
// for (int i=0; i<=Q; i++) {
// if (X[i])
// }
//
// }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, ans = 0;
cin >> n;
for (long long m = 1; m <= sqrt(n); m++) {
if (n % (m + 1) && n / (m + 1) == n / m)
ans += m;
if (n % m)
continue;
long long mm = n / m - 1;
// if (mm * mm < n) break;
if (n / (mm + 1) == n / mm)
ans += mm;
}
cout << ans << endl;
// int T;
// cin>>T;
// for (int t=1; t<=T; t++) {
// cout<<"Case #"<<t<<": ";
// solve();
// }
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
// int X[100000], Y[100000];
//
// void solve() {
// int P, Q, x, y;
// char d;
// cin>>P>>Q;
// memset(X, 0, sizeof(X));
// memset(Y, 0, sizeof(Y));
// for (int i=0; i<P; i++) {
// cin>>x>>y>>d;
// if (d == 'N') for (int j= y+1; j<=Q; j++) Y[j]++;
// if (d == 'S') for (int j= 0; j<y; j++) Y[j]++;
// if (d == 'E') for (int j= x+1; x<=Q; j++) X[j]++;
// if (d == 'W') for (int j= 0; j<x; j++) X[j]++;
// }
// int ans = 0;
// for (int i=0; i<=Q; i++) {
// if (X[i])
// }
//
// }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, ans = 0;
cin >> n;
for (long long m = 1; m <= sqrt(n); m++) {
if (n % (m + 1) && n / (m + 1) == n / m)
ans += m;
if (n % m)
continue;
long long mm = n / m - 1;
// if (mm * mm < n) break;
if (mm && n / (mm + 1) == n / mm)
ans += mm;
}
cout << ans << endl;
// int T;
// cin>>T;
// for (int t=1; t<=T; t++) {
// cout<<"Case #"<<t<<": ";
// solve();
// }
return 0;
} | replace | 63 | 64 | 63 | 64 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; // x軸方向への変位
ll dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; // y軸方向への変位
ll n;
string a;
vector<string> ans;
string c = "abcdefghijklm";
int main(void) {
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= sqrt(n); i++) {
ll check = n - i;
ll b = check / i;
if (check % i == 0 && n % b == i) {
ans += check / i;
// cout << i << " " << n%b<< endl;
}
}
// cout << 2499687339915-2499686339916 << endl;
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; // x軸方向への変位
ll dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; // y軸方向への変位
ll n;
string a;
vector<string> ans;
string c = "abcdefghijklm";
int main(void) {
ll n;
cin >> n;
ll ans = 0;
if (n > 1) {
for (ll i = 1; i <= sqrt(n); i++) {
ll check = n - i;
ll b = check / i;
if (check % i == 0 && n % b == i)
ans += check / i;
}
}
// cout << 2499687339915-2499686339916 << endl;
cout << ans << endl;
return 0;
}
| replace | 25 | 31 | 25 | 31 | 0 | |
p03050 | C++ | Runtime Error | #pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define PER(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(V) (V).begin(), (V).end()
#define SORT(V) sort(ALL(V)) // 小さい方からソート
#define REV(V) reverse(ALL(V)) // リバース
#define RSORT(V) \
SORT(V); \
REV(V) // 大きい方からソート
#define NEXP(V) next_permutation(ALL(V)) // 順列
#define pb(n) push_back(n)
#define popb(n) pop_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a, b, c) (a) < (b) && (b) < (c)
#define MIDe(a, b, c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define IN4(a, b, c, d) cin >> a >> b >> c >> d
#define VIN(V) \
for (int i = 0; i < (V).size(); i++) { \
cin >> (V).at(i); \
}
#define OUT(n) cout << n << endl
#define VOUT(V) \
REP(i, (V).size()) { cout << (V)[i] << endl; }
#define VOUT2(V) \
REP(i, (V).size()) { \
if ((V).size() - 1 != i) { \
cout << (V)[i] << " "; \
} else { \
cout << (V)[i] << endl; \
} \
}
#define int long long
#define P pair<ll, ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll, ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue < ll, V, greater<ll>
using ll = long long;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
class UnionFind {
public:
vector<int> par;
vector<int> siz;
UnionFind(int sz_) : par(sz_), siz(sz_, 1LL) {
for (int i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (int i = 0; i < sz_; ++i)
par[i] = i;
}
int root(int x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(int x, int y) { return root(x) == root(y); }
int size(int x) { return siz[root(x)]; }
};
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
// 文字を全て大文字にします
string toStrUp(string str) {
char diff = 'A' - 'a';
REP(i, str.size()) str[i] += diff;
return str;
}
// 文字をstring型で一文字取得します
string get1ch(string str, int key) { return str.substr(key, 1); }
// 素因数分解 (O(sqrt(n)))
map<int, int> prime_factor(int n) {
map<int, int> ret;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
// 素数判定 (O(sqrt(n)))
bool is_prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return true;
}
// 進数変換 (O(log n))
template <typename T> vector<T> convert_base(T x, T b) {
vector<T> ret;
T t = 1, k = abs(b);
while (x) {
ret.emplace_back((x * t) % k);
if (ret.back() < 0)
ret.back() += k;
x -= ret.back() * t;
x /= k;
t *= b / k;
}
if (ret.empty())
ret.emplace_back(0);
reverse(begin(ret), end(ret));
return ret;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int modPow(int a, int n) {
if (n == 1)
return a % MOD;
if (n % 2 == 1)
return (a * modPow(a, n - 1)) % MOD;
int t = modPow(a, n / 2);
return (t * t) % MOD;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
// デフォルト変数定義
int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0;
string s = "", t = "";
//
// ここから
IN(n);
int ans = 0;
for (int same = 1; same * same <= n; ++same) {
if ((n - same) % same == 0) {
m = (n - same) / same;
if (n / m == n % m) {
ans += m;
}
}
}
OUT(ans);
} | #pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define PER(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(V) (V).begin(), (V).end()
#define SORT(V) sort(ALL(V)) // 小さい方からソート
#define REV(V) reverse(ALL(V)) // リバース
#define RSORT(V) \
SORT(V); \
REV(V) // 大きい方からソート
#define NEXP(V) next_permutation(ALL(V)) // 順列
#define pb(n) push_back(n)
#define popb(n) pop_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a, b, c) (a) < (b) && (b) < (c)
#define MIDe(a, b, c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define IN4(a, b, c, d) cin >> a >> b >> c >> d
#define VIN(V) \
for (int i = 0; i < (V).size(); i++) { \
cin >> (V).at(i); \
}
#define OUT(n) cout << n << endl
#define VOUT(V) \
REP(i, (V).size()) { cout << (V)[i] << endl; }
#define VOUT2(V) \
REP(i, (V).size()) { \
if ((V).size() - 1 != i) { \
cout << (V)[i] << " "; \
} else { \
cout << (V)[i] << endl; \
} \
}
#define int long long
#define P pair<ll, ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll, ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue < ll, V, greater<ll>
using ll = long long;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
class UnionFind {
public:
vector<int> par;
vector<int> siz;
UnionFind(int sz_) : par(sz_), siz(sz_, 1LL) {
for (int i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (int i = 0; i < sz_; ++i)
par[i] = i;
}
int root(int x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(int x, int y) { return root(x) == root(y); }
int size(int x) { return siz[root(x)]; }
};
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
// 文字を全て大文字にします
string toStrUp(string str) {
char diff = 'A' - 'a';
REP(i, str.size()) str[i] += diff;
return str;
}
// 文字をstring型で一文字取得します
string get1ch(string str, int key) { return str.substr(key, 1); }
// 素因数分解 (O(sqrt(n)))
map<int, int> prime_factor(int n) {
map<int, int> ret;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
// 素数判定 (O(sqrt(n)))
bool is_prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return true;
}
// 進数変換 (O(log n))
template <typename T> vector<T> convert_base(T x, T b) {
vector<T> ret;
T t = 1, k = abs(b);
while (x) {
ret.emplace_back((x * t) % k);
if (ret.back() < 0)
ret.back() += k;
x -= ret.back() * t;
x /= k;
t *= b / k;
}
if (ret.empty())
ret.emplace_back(0);
reverse(begin(ret), end(ret));
return ret;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int modPow(int a, int n) {
if (n == 1)
return a % MOD;
if (n % 2 == 1)
return (a * modPow(a, n - 1)) % MOD;
int t = modPow(a, n / 2);
return (t * t) % MOD;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
// デフォルト変数定義
int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0;
string s = "", t = "";
//
// ここから
IN(n);
int ans = 0;
for (int same = 1; same * same <= n; ++same) {
if ((n - same) % same == 0) {
m = (n - same) / same;
if (m == 0) {
continue;
}
if (n / m == n % m) {
ans += m;
}
}
}
OUT(ans);
} | insert | 205 | 205 | 205 | 208 | 0 | |
p03050 | C++ | Time Limit Exceeded | #if 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;
#define LOADVEC(type, name, N) \
std::vector<type> name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name[nnn]; \
}
#define LOADVEC2(type, name0, name1, N) \
std::vector<type> name0(N), name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
}
#define LOADVEC3(type, name0, name1, name2, N) \
std::vector<type> name0(N), name1(N), name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
cin >> name2[nnn]; \
}
#define LOAD(type, name) \
type name; \
cin >> name;
void proc();
signed main() {
ios::sync_with_stdio(false);
proc();
return 0;
}
/*
--------------------------------------------------------
--------------------------------------------------------
--------------- template ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/
void proc() {
LOAD(int, N);
if (N == 2) {
cout << 0 << endl;
return;
}
int res = 0;
for (int a = 1;; ++a) {
if (N % a != 0)
continue;
int m = N / a - 1;
if (a >= m)
break;
res += m;
}
cout << res << endl;
}
#endif
| #if 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
#define uint unsigned long long
constexpr int MOD = 1000000007;
constexpr int INF = 1145141919810893;
#define LOADVEC(type, name, N) \
std::vector<type> name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name[nnn]; \
}
#define LOADVEC2(type, name0, name1, N) \
std::vector<type> name0(N), name1(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
}
#define LOADVEC3(type, name0, name1, name2, N) \
std::vector<type> name0(N), name1(N), name2(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
cin >> name0[nnn]; \
cin >> name1[nnn]; \
cin >> name2[nnn]; \
}
#define LOAD(type, name) \
type name; \
cin >> name;
void proc();
signed main() {
ios::sync_with_stdio(false);
proc();
return 0;
}
/*
--------------------------------------------------------
--------------------------------------------------------
--------------- template ----------------------
--------------------------------------------------------
--------------------------------------------------------
*/
void proc() {
LOAD(int, N);
if (N == 2) {
cout << 0 << endl;
return;
}
int res = 0;
for (int a = 1;; ++a) {
double m_ = 1.0 * N / a - 1;
if (a >= m_)
break;
if (N % a != 0)
continue;
int m = N / a - 1;
if (a >= m)
break;
res += m;
}
cout << res << endl;
}
#endif
| insert | 70 | 70 | 70 | 73 | TLE | |
p03050 | C++ | Runtime Error | #include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
long long ans = 0;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i > 1) {
if (n / (i - 1) == n % (i - 1)) {
ans += i - 1;
}
}
long long d = n / i - 1;
if (n / d == n % d) {
ans += d;
}
}
}
printf("%lld\n", ans);
return 0;
} | #include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
long long ans = 0;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i > 1) {
if (n / (i - 1) == n % (i - 1)) {
ans += i - 1;
}
}
long long d = n / i - 1;
if (d > 0) {
if (n / d == n % d) {
ans += d;
}
}
}
}
printf("%lld\n", ans);
return 0;
} | replace | 14 | 16 | 14 | 18 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
int main() {
int64_t N, answer = 0;
cin >> N;
for (int64_t i = 1; i < N; i++) {
if (N % i == N / i)
answer += i;
}
cout << answer;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
int main() {
int64_t N, answer = 0;
cin >> N;
for (int64_t i = 1; i * i < N; i++) {
if (N % i == 0 && i < (N / i) - 1)
answer += (N / i) - 1;
}
cout << answer;
}
| replace | 8 | 11 | 8 | 11 | TLE | |
p03050 | C++ | Time Limit Exceeded | // include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int MOD = 1000000007;
// MOD
//--------------------------------------------
#define MUL(a, b) (((a) % MOD) * ((b) % MOD)) % MOD
// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};
// debug
//--------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
// IO accelerate
//--------------------------------------------
struct InitIO {
InitIO() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
} init_io;
// main code
int main(int argc, char const *argv[]) {
LL n;
cin >> n;
LL ans = 0;
for (LL i = 1; i < min(n, (LL)500000000); i++) {
if ((n - i) % i == 0) {
if ((n - i) / i <= i) {
break;
}
ans += (n - i) / i;
}
}
cout << ans << endl;
return 0;
}
| // include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int MOD = 1000000007;
// MOD
//--------------------------------------------
#define MUL(a, b) (((a) % MOD) * ((b) % MOD)) % MOD
// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};
// debug
//--------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
// IO accelerate
//--------------------------------------------
struct InitIO {
InitIO() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
} init_io;
// main code
int main(int argc, char const *argv[]) {
LL n;
cin >> n;
LL ans = 0;
for (LL i = 1; i < min(n, (LL)10000000); i++) {
if ((n - i) % i == 0) {
if ((n - i) / i <= i) {
break;
}
ans += (n - i) / i;
}
}
cout << ans << endl;
return 0;
}
| replace | 65 | 66 | 65 | 66 | TLE | |
p03050 | C++ | Runtime Error |
// #define NDEBUG
#pragma GCC optimize("O3") // 最適化レベルの変更 O0〜O3 などを指定
#pragma GCC optimize("-O3,inline,omit-frame-pointer,unroll-loops")
#pragma warning(1 : 4456) // 多重forループ内での変数の2重定義を警告にする
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <memory>
#include <chrono>
#include <functional>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
namespace ValLib {
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
constexpr ull V_MOD = 1000000007ull;
constexpr int V_INT_MAX = 2147483647;
constexpr ll V_LL_MAX = 9223372036854775807ll;
constexpr ull V_ULL_MAX = 18446744073709551615ull;
template <typename Key, typename Value>
using umap = std::unordered_map<Key, Value>;
template <typename T> using uset = std::unordered_set<T>;
template <typename T> using sptr = typename std::shared_ptr<T>;
class vnode;
class vegde;
class vgraph;
template <typename T> void fill(vector<T> &vec, const T &value) {
std::fill(vec.begin(), vec.end(), value);
}
template <typename T> void fill(vector<vector<T>> &vec, const T &value) {
for (vector<T> &t : vec)
std::fill(t.begin(), t.end(), value);
}
template <typename T> void resize(vector<T> &vec, int size1) {
vec.resize(size1);
}
template <typename T> void resize(vector<T> &vec, int size1, const T &value) {
vec.resize(size1, value);
}
template <typename T>
void resize(vector<vector<T>> &vec, int size1, int size2) {
vec.resize(size1);
for (vector<T> &t : vec)
t.resize(size2);
}
template <typename T>
void resize(vector<vector<T>> &vec, int size1, int size2, const T &value) {
vec.resize(size1);
for (vector<T> &t : vec)
t.resize(size2, value);
}
template <typename T> void assign(vector<T> &vec, int size1, const T &value) {
vec.assign(size1, value);
}
template <typename T>
void assign(vector<vector<T>> &vec, int size1, int size2, const T &value) {
vec.resize(size1);
for (vector<T> &t : vec)
t.assign(size2, value);
}
template <typename T>
const typename vector<T>::const_iterator max_element(const vector<T> &vec) {
assert(!vec.empty());
return std::max_element(vec.begin(), vec.end());
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator max_element(const vector<T> &vec,
_Pr lessThan) {
assert(!vec.empty());
return std::max_element(vec.begin(), vec.end(), lessThan);
}
template <typename T> typename vector<T>::iterator min_element(vector<T> &vec) {
assert(!vec.empty());
return std::min_element(vec.begin(), vec.end());
}
template <typename T>
const typename vector<T>::const_iterator min_element(const vector<T> &vec) {
assert(!vec.empty());
return std::min_element(vec.begin(), vec.end());
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator min_element(const vector<T> &vec,
_Pr lessThan) {
assert(!vec.empty());
return std::min_element(vec.begin(), vec.end(), lessThan);
}
int accumulate(const vector<int> &vec) {
return std::accumulate(vec.begin(), vec.end(), 0);
}
template <typename _Pr> int accumulate(const vector<int> &vec, _Pr func) {
return std::accumulate(vec.begin(), vec.end(), 0, func);
}
double accumulate(const vector<double> &vec) {
return std::accumulate(vec.begin(), vec.end(), 0.0);
}
template <typename _Pr> double accumulate(const vector<double> &vec, _Pr func) {
return std::accumulate(vec.begin(), vec.end(), 0.0, func);
}
float accumulate(const vector<float> &vec) {
return std::accumulate(vec.begin(), vec.end(), 0.f);
}
template <typename _Pr> float accumulate(const vector<float> &vec, _Pr func) {
return std::accumulate(vec.begin(), vec.end(), 0.f, func);
}
template <typename T, typename _Pr>
bool all_of(const vector<T> &vec, _Pr pred) {
return std::all_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool any_of(const vector<T> &vec, _Pr pred) {
return std::any_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool none_of(const vector<T> &vec, _Pr pred) {
return std::none_of(vec.begin(), vec.end(), pred);
}
template <typename T>
const typename vector<T>::const_iterator find(const vector<T> &vec,
const T &val) {
return std::find(vec.begin(), vec.end(), val);
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator find_if(const vector<T> &vec,
_Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred);
}
template <typename T> bool contains(const vector<T> &vec, const T &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
}
template <typename T, typename _Pr>
bool contains_if(const vector<T> &vec, _Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred) != vec.end();
}
template <typename T, typename _Pr>
typename iterator_traits<
const typename vector<T>::const_iterator>::difference_type
count_if(const vector<T> &vec, _Pr pred) {
return std::count_if(vec.begin(), vec.end(), pred);
}
template <typename T> void sort(vector<T> &vec) {
std::sort(vec.begin(), vec.end());
}
template <typename T, typename _Pr> void sort(vector<T> &vec, _Pr pred) {
std::sort(vec.begin(), vec.end(), pred);
}
template <typename T> void stable_sort(vector<T> &vec) {
std::stable_sort(vec.begin(), vec.end());
}
template <typename T, typename _Pr> void stable_sort(vector<T> &vec, _Pr pred) {
std::stable_sort(vec.begin(), vec.end(), pred);
}
template <typename T, size_t N> void fill(array<T, N> &ary, const T &value) {
std::fill(ary.begin(), ary.end(), value);
}
template <typename T, size_t N, size_t M>
void fill(array<array<T, M>, N> &ary, const T &value) {
for (array<T, M> &t : ary)
std::fill(t.begin(), t.end(), value);
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator max_element(const array<T, N> &ary) {
assert(!ary.empty());
return std::max_element(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
const typename vector<T>::const_iterator max_element(const array<T, N> &ary) {
assert(!ary.empty());
return std::max_element(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator max_element(const array<T, N> &ary,
_Pr lessThan) {
assert(!ary.empty());
return std::max_element(ary.begin(), ary.end(), lessThan);
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator min_element(const array<T, N> &ary) {
assert(!ary.empty());
return std::min_element(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator min_element(const array<T, N> &ary,
_Pr lessThan) {
assert(!ary.empty());
return std::min_element(ary.begin(), ary.end(), lessThan);
}
template <size_t N> int accumulate(const array<int, N> &ary) {
return std::accumulate(ary.begin(), ary.end(), 0);
}
template <size_t N, typename _Pr>
int accumulate(const array<int, N> &ary, _Pr func) {
return std::accumulate(ary.begin(), ary.end(), 0, func);
}
template <size_t N> double accumulate(const array<double, N> &ary) {
return std::accumulate(ary.begin(), ary.end(), 0.0);
}
template <size_t N, typename _Pr>
double accumulate(const array<double, N> &ary, _Pr func) {
return std::accumulate(ary.begin(), ary.end(), 0.0, func);
}
template <size_t N> float accumulate(const array<float, N> &ary) {
return std::accumulate(ary.begin(), ary.end(), 0.f);
}
template <size_t N, typename _Pr>
float accumulate(const array<float, N> &ary, _Pr func) {
return std::accumulate(ary.begin(), ary.end(), 0.f, func);
}
template <typename T, size_t N, typename _Pr>
bool all_of(const array<T, N> &ary, _Pr pred) {
return std::all_of(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N, typename _Pr>
bool any_of(const array<T, N> &ary, _Pr pred) {
return std::any_of(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N, typename _Pr>
bool none_of(const array<T, N> &ary, _Pr pred) {
return std::none_of(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N>
const typename array<T, N>::const_iterator find(const array<T, N> &ary,
const T &val) {
return std::find(ary.begin(), ary.end(), val);
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator find_if(const array<T, N> &ary,
_Pr pred) {
return std::find_if(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N>
bool contains(const array<T, N> &ary, const T &val) {
return std::find(ary.begin(), ary.end(), val) != ary.end();
}
template <typename T, size_t N, typename _Pr>
bool contains_if(const array<T, N> &ary, _Pr pred) {
return std::find_if(ary.begin(), ary.end(), pred) != ary.end();
}
template <typename T, size_t N, typename _Pr>
typename iterator_traits<
const typename array<T, N>::const_iterator>::difference_type
count_if(const array<T, N> &ary, _Pr pred) {
return std::count_if(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N> void sort(array<T, N> &ary) {
std::sort(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
void sort(array<T, N> &ary, _Pr pred) {
std::sort(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N> void stable_sort(array<T, N> &ary) {
std::stable_sort(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
void stable_sort(array<T, N> &ary, _Pr pred) {
std::stable_sort(ary.begin(), ary.end(), pred);
}
template <typename Key, typename Value>
bool containsKey(const umap<Key, Value> &m, const Key &key) {
return m.find(key) != m.end();
}
template <typename Key, typename Value>
bool containsValue(const umap<Key, Value> &m, const Value &val) {
for (auto it = m.begin(); it != m.end(); ++it)
if (it->second == val)
return true;
return false;
}
template <typename T>
const typename uset<T>::const_iterator find(const uset<T> &s, const T &key) {
return s.find(key);
}
template <typename T> bool contains(const uset<T> &s, const T &key) {
return s.find(key) != s.end();
}
constexpr int DX4[] = {0, -1, 0, 1};
constexpr int DY4[] = {-1, 0, 1, 0};
constexpr int DX8[] = {0, -1, -1, -1, 0, 1, 1, 1};
constexpr int DY8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
constexpr int DX5[] = {DX4[0], DX4[1], DX4[2], DX4[3], 0};
constexpr int DY5[] = {DY4[0], DY4[1], DY4[2], DY4[3], 0};
constexpr int DX9[] = {DX8[0], DX8[1], DX8[2], DX8[3], DX8[4],
DX8[5], DX8[6], DX8[7], 0};
constexpr int DY9[] = {DY8[0], DY8[1], DY8[2], DY8[3], DY8[4],
DY8[5], DY8[6], DY8[7], 0};
class Point {
public:
constexpr inline Point() : Point(-1, -1) {}
constexpr inline Point(int x, int y) : x(x), y(y) {}
static Point getManhattanDist(const Point &p1, const Point &p2) {
return move(Point(abs(p1.x - p2.x), abs(p1.y - p2.y)));
}
void setPos(const Point &pos) {
x = pos.x;
y = pos.y;
}
void setPos(int x, int y) {
this->x = x;
this->y = y;
}
Point operator+(int val) const { return move(Point(x + val, y + val)); }
Point operator-(int val) const { return move(Point(x - val, y - val)); }
Point operator*(int val) const { return move(Point(x * val, y * val)); }
Point operator/(int val) const { return move(Point(x / val, y / val)); }
Point operator+(const Point &p) const {
return move(Point(x + p.x, y + p.y));
}
Point operator-(const Point &p) const {
return move(Point(x - p.x, y - p.y));
}
Point operator*(const Point &p) const {
return move(Point(x * p.x, y * p.y));
}
Point operator/(const Point &p) const {
return move(Point(x / p.x, y / p.y));
}
void operator+=(int val) {
x += val;
y += val;
}
void operator-=(int val) {
x -= val;
y -= val;
}
void operator*=(int val) {
x *= val;
y *= val;
}
void operator/=(int val) {
x /= val;
y /= val;
}
void operator+=(const Point &p) {
x += p.x;
y += p.y;
}
void operator-=(const Point &p) {
x -= p.x;
y -= p.y;
}
void operator*=(const Point &p) {
x *= p.x;
y *= p.y;
}
void operator/=(const Point &p) {
x /= p.x;
y /= p.y;
}
bool operator==(const Point &p) const { return x == p.x && y == p.y; }
bool operator!=(const Point &p) const { return x != p.x || y != p.y; }
// bool operator<(const Point &p) const {return x * x + y * y < p.x * p.x +
// p.y * p.y;}
const Point &getPos() const { return *this; }
string to_string() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}
int x, y;
};
constexpr Point DP4[] = {Point(DX4[0], DY4[0]), Point(DX4[1], DY4[1]),
Point(DX4[2], DY4[2]), Point(DX4[3], DY4[3])};
constexpr Point DP5[] = {Point(DX5[0], DY5[0]), Point(DX5[1], DY5[1]),
Point(DX5[2], DY5[2]), Point(DX5[3], DY5[3]),
Point(DX5[4], DY5[4])};
constexpr Point DP8[] = {Point(DX8[0], DY8[0]), Point(DX8[1], DY8[1]),
Point(DX8[2], DY8[2]), Point(DX8[3], DY8[3]),
Point(DX8[4], DY8[4]), Point(DX8[5], DY8[5]),
Point(DX8[6], DY8[6]), Point(DX8[7], DY8[7])};
constexpr Point DP9[] = {Point(DX9[0], DY9[0]), Point(DX9[1], DY9[1]),
Point(DX9[2], DY9[2]), Point(DX9[3], DY9[3]),
Point(DX9[4], DY9[4]), Point(DX9[5], DY9[5]),
Point(DX9[6], DY9[6]), Point(DX9[7], DY9[7])};
// 定数時間初期化配列 (Constant Time Initializable Array)
template <typename _Vt, size_t _Sz> class CTInitArray : public array<_Vt, _Sz> {
public:
CTInitArray() = default;
CTInitArray(const _Vt &initVal) : mCurrentNum(1), mInitVal(initVal) {
std::fill(mNums.begin(), mNums.end(), 0);
}
inline void setInitVal(const _Vt &initVal) { mInitVal = initVal; }
inline void init() { ++mCurrentNum; }
inline const _Vt &read(size_t index) const {
return (mNums[index] == mCurrentNum) ? array<_Vt, _Sz>::operator[](index)
: mInitVal;
}
inline const _Vt &write(size_t index, const _Vt &val) {
mNums[index] = mCurrentNum;
return array<_Vt, _Sz>::operator[](index) = val;
}
private:
inline const _Vt &operator[](size_t index) const {
return (mNums[index] == mCurrentNum) ? array<_Vt, _Sz>::operator[](index)
: mInitVal;
}
_Vt mInitVal;
array<int, _Sz> mNums;
int mCurrentNum;
};
// 定数時間初期化配列2次元 (Constant Time Initializable Array)
template <typename _Vt, size_t _Sz1, size_t _Sz2>
class CTInitArray2D : public array<array<_Vt, _Sz2>, _Sz1> {
public:
CTInitArray2D() = default;
CTInitArray2D(const _Vt &initVal) : mCurrentNum(1), mInitVal(initVal) {
for (array<int, _Sz2> &t1 : mNums)
std::fill(t1.begin(), t1.end(), 0);
}
inline void setInitVal(const _Vt &initVal) { mInitVal = initVal; }
inline void init() { ++mCurrentNum; }
inline const _Vt &read(size_t index1, size_t index2) {
return (mNums[index1][index2] == mCurrentNum)
? array<array<_Vt, _Sz2>, _Sz1>::operator[](index1)[index2]
: mInitVal;
}
inline const _Vt &write(size_t index1, size_t index2, const _Vt &val) {
mNums[index1][index2] = mCurrentNum;
return array<array<_Vt, _Sz2>, _Sz1>::operator[](index1)[index2] = val;
}
private:
inline _Vt &operator[](size_t _Pos) {
return array<array<_Vt, _Sz2>, _Sz1>::operator[](_Pos);
} // 封印
_Vt mInitVal;
array<array<int, _Sz2>, _Sz1> mNums;
int mCurrentNum;
};
// 定数時間初期化配列3次元 (Constant Time Initializable Array)
template <typename _Vt, size_t _Sz1, size_t _Sz2, size_t _Sz3>
class CTInitArray3D : public array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1> {
public:
CTInitArray3D() = default;
CTInitArray3D(const _Vt &initVal) : mCurrentNum(1), mInitVal(initVal) {
for (array<array<int, _Sz3>, _Sz2> &t1 : mNums)
for (array<int, _Sz3> &t2 : t1)
std::fill(t2.begin(), t2.end(), 0);
}
inline void setInitVal(const _Vt &initVal) { mInitVal = initVal; }
inline void init() { ++mCurrentNum; }
inline const _Vt &read(size_t index1, size_t index2, size_t index3) {
return (mNums[index1][index2][index3] == mCurrentNum)
? array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1>::operator[](
index1)[index2][index3]
: mInitVal;
}
inline const _Vt &write(size_t index1, size_t index2, size_t index3,
const _Vt &val) {
mNums[index1][index2][index3] = mCurrentNum;
return array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1>::operator[](
index1)[index2][index3] = val;
}
private:
inline _Vt &operator[](size_t _Pos) {
return array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1>::operator[](_Pos);
} // 封印
_Vt mInitVal;
array<array<array<int, _Sz3>, _Sz2>, _Sz1> mNums;
int mCurrentNum;
};
static constexpr int COMBI_MAX = 500000; // nCrのnとrの最大値
static ull gFact[COMBI_MAX + 1]; // modの世界での階乗
static ull gInv[COMBI_MAX + 1]; // modの世界での逆元
static ull gFactInv[COMBI_MAX + 1]; // modの世界での逆元の階乗
static ull gCombiInitMod = 0; // 組み合わせの計算に使用したmod値
namespace vmath {
static constexpr ull mod_add(ull a, ull b, ull mod) {
return ((a % mod) + (b % mod)) % mod;
}
static constexpr ull mod_sub(ull a, ull b, ull mod) {
// a>bだとmod-(b-a)が返る
return ((a % mod) + mod - (b % mod)) % mod;
}
static constexpr ull mod_mul(ull a, ull b, ull mod) {
return ((a % mod) * (b % mod)) % mod;
}
// 最大公約数(ユーグリッドの互除法)
static constexpr ull gcd(ull x, ull y) {
assert(x > 0ull);
assert(y > 0ull);
ull r = 0ull;
while ((r = x % y) != 0ull) {
x = y;
y = r;
}
return y;
}
// 最小公倍数
static constexpr ull lcm(ull x, ull y) {
assert(x > 0ull);
assert(y > 0ull);
return x / gcd(x, y) * y;
}
// 約数を全て求める O(√n)
static ull calcDivisors(list<ull> *divisors, ull n) {
divisors->clear();
if (n <= 0ull) {
return 0ull;
}
divisors->push_back(1ull);
if (n != 1ull) {
divisors->push_back(n);
}
for (ull i = 2ull; i * i <= n; ++i) {
if (n % i == 0ull) {
divisors->push_back(i);
if (i != n / i) {
divisors->push_back(n / i);
}
}
}
return divisors->size();
}
// 約数の個数を返す O(√n)
static ull calcDivisorNum(ull n) {
if (n <= 0ull) {
return 0ull;
}
ull count = 1ull; // for 1
if (n != 1ull) {
++count; // for n
}
// for 2~n-1
for (ull i = 2ull; i * i <= n; ++i) {
if (n % i == 0ull) {
count += 1ull;
if (i != n / i) {
count += 1ull;
}
}
}
return count;
}
// 素因数分解 O(√n)
static int calcDecompositPrime(list<ull> *primes, ull n) {
primes->clear();
if (n == 0) {
return 0ull;
}
if (n == 1) {
primes->push_back(1);
return 1ull;
}
// 割る数の初期値
ull a = 2ull;
// √n ≧ a ( n ≧ a * a ) の間ループ処理
while (n >= a * a) {
if (n % a == 0ull) {
// a で割り切れたら、a は素因数
primes->push_back(a);
// そして、割られる数を a で割る
n /= a;
} else {
// a で割り切れなかったら、 a を 1 増加させる
a++;
}
}
primes->push_back(n);
return primes->size();
}
// 素因数の数を返す O(√n)
static ull calcDecompositPrimeNum(ull n) {
if (n <= 1) {
return n;
}
ull count = 0ull;
// 割る数の初期値
ull a = 2ull;
// √n ≧ a ( n ≧ a * a ) の間ループ処理
while (n >= a * a) {
if (n % a == 0ull) {
// a で割り切れたら、a は素因数
++count;
// そして、割られる数を a で割る
n /= a;
} else {
// a で割り切れなかったら、 a を 1 増加させる
a++;
}
}
++count; // for n
return count;
}
// 階乗
static constexpr ull fact(ull x, ull mod) {
ull result = 1ull;
for (ull i = 1ull; i <= x; ++i) {
if (mod == 0ull) {
result *= i;
} else {
result = mod_mul(result, i, mod);
}
}
return result;
}
// 階乗
static constexpr ull fact(ull x) { return fact(x, 0ull); }
// 順列の個数 nPr
static constexpr ull permutation(ull n, ull r, ull mod) {
assert(n >= r);
if (n == 0ull || r == 0ull) {
return 0ull;
}
// return fact(n) / fact(n - r);
ull result = 1ull;
for (ull i = n; i > n - r; --i) {
if (mod == 0ull) {
result *= i;
} else {
result = mod_mul(result, i, mod);
}
}
return result;
}
// 順列の個数 nPr
static constexpr ull permutation(ull n, ull r) {
return permutation(n, r, 0ull);
}
// 組み合わせテーブルを作る
static void initCombination(ull mod) {
gFact[0] = gFact[1] = 1;
gFactInv[0] = gFactInv[1] = 1;
gInv[1] = 1;
for (int i = 2; i <= COMBI_MAX; i++) {
gFact[i] = gFact[i - 1] * i % mod;
gInv[i] = mod - gInv[mod % i] * (mod / i) % mod;
gFactInv[i] = gFactInv[i - 1] * gInv[i] % mod;
}
gCombiInitMod = mod;
}
static void initCombination() { initCombination(V_MOD); }
// 組み合わせの数を計算
static long long combination(ull n, ull k) {
assert(gCombiInitMod > 0 && "先にinitCombinationを呼び出して");
assert(n <= (ull)COMBI_MAX);
assert(k <= (ull)COMBI_MAX);
if (n < k)
return 0;
return (gFact[n] * ((gFactInv[k] * gFactInv[n - k]) % V_MOD)) % V_MOD;
}
// 重複組合せ nHr = n+r-1Cr
// 使いどころ:n人にr個を配るとき、同じ人に何個配っても良い場合とか
// 4人に5個の◯を配るときa=2,b=0,c=2,d=1のとき、◯◯||◯◯|◯みたいになる。
// これは◯と|を混ぜた組み合わせで、◯の数がn,棒の数はr-1だから全体でn+r-1
// (n-r)で割ったものが順列n+r-1Prで、それを更にrで割っているからnHr = n+r-1Cr
static ull repeatedCombination(ull n, ull r) {
return combination(n + r - 1, r);
}
// xのN乗を求める(バイナリ法) O(logN)
static constexpr ull intPow(ull x, ull n, ull mod) {
assert(x >= 0ull);
assert(n >= 0ull);
if (x == 0ull) {
if (n == 0ull) {
return 1ull;
} else {
return 0ull;
}
}
ull result = 1ull;
ull z = x;
while (n > 0ull) {
if (n & 1ull) {
if (mod > 0ull) {
result = mod_mul(result, z, mod);
} else {
result *= z;
}
}
if (mod > 0ull) {
z = mod_mul(z, z, mod);
} else {
z *= z;
}
n >>= 1ull;
}
return result;
}
// xのN乗を求める(バイナリ法) O(logN)
static constexpr ull intPow(ull x, ull n) { return intPow(x, n, 0ull); }
// xのN桁目の数値を得る
static constexpr ull getNDigitNumber(ull x, ull n) {
assert(n > 0);
assert(n <= 20);
return (x / intPow(10ull, n - 1ull)) % 10;
}
}; // namespace vmath
class vegde {
public:
vegde() : vegde(-1) {}
vegde(int cost) : mCost(cost) {}
int getCost() const { return mCost; }
private:
int mCost;
};
class vnode {
public:
vnode() : vnode(-1) {}
vnode(int id) : mID(id) {}
void addEgde(const vegde &egde, const vnode *node) {
mEgdeList.emplace_back(egde, node);
}
void removeEgde(int nodeID) {
auto itrNewEnd =
std::remove_if(mEgdeList.begin(), mEgdeList.end(),
[=](const pair<vegde, const vnode *> &p) -> bool {
return (p.second->getID() == nodeID);
});
mEgdeList.erase(itrNewEnd, mEgdeList.end());
}
int getID() const { return mID; }
const list<pair<vegde, const vnode *>> &getEgde() const { return mEgdeList; }
private:
list<pair<vegde, const vnode *>> mEgdeList;
int mID;
};
class AdjacencyMatrix {
public:
AdjacencyMatrix() = default;
AdjacencyMatrix(int nodeNum) {
resize(mConnectionMap, nodeNum, nodeNum);
resize(mCostMap, nodeNum, nodeNum);
resize(mMinimumDistMap, nodeNum, nodeNum);
}
// virtual void addEdge(int nodeID1, int nodeID2, int cost) = 0;
// virtual void removeEgde(int nodeID1, int nodeID2) = 0;
void warshallFloyd(int nodeNum) {
for (int k = 0; k < nodeNum; ++k) {
for (int i = 0; i < nodeNum; ++i) {
for (int j = 0; j < nodeNum; ++j) {
if (mConnectionMap[i][j]) {
mMinimumDistMap[i][j] = mCostMap[i][j];
} else {
mMinimumDistMap[i][j] = 99999999;
}
}
}
}
for (int k = 0; k < nodeNum; ++k) {
for (int i = 0; i < nodeNum; ++i) {
for (int j = 0; j < nodeNum; ++j) {
mMinimumDistMap[i][j] =
min(mMinimumDistMap[i][j],
mMinimumDistMap[i][k] + mMinimumDistMap[k][j]);
}
}
}
// for (int i = 0; i < mNodeNum; ++i) {
// for (int j = 0; j < mNodeNum; ++j) {
// cerr << mMinimumDistMap[i][j] << ", ";
// }
// cerr << endl;
// }
}
const vector<vector<bool>> &getConnectionMap() const {
return mConnectionMap;
}
const vector<vector<int>> &getCostMap() const { return mCostMap; }
const vector<vector<int>> &getMinimumDistMap() const {
return mMinimumDistMap;
}
protected:
vector<vector<bool>> mConnectionMap;
vector<vector<int>> mCostMap;
vector<vector<int>> mMinimumDistMap;
};
class DirectedAdjacencyMatrix : public AdjacencyMatrix {
public:
DirectedAdjacencyMatrix() = default;
DirectedAdjacencyMatrix(int nodeNum) : AdjacencyMatrix(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mConnectionMap[nodeID1][nodeID2] = true;
mCostMap[nodeID1][nodeID2] = cost;
}
void removeEgde(int nodeID1, int nodeID2) {
mConnectionMap[nodeID1][nodeID2] = false;
mCostMap[nodeID1][nodeID2] = 0;
}
};
class UndirectedAdjacencyMatrix : public AdjacencyMatrix {
public:
UndirectedAdjacencyMatrix() = default;
UndirectedAdjacencyMatrix(int nodeNum) : AdjacencyMatrix(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mConnectionMap[nodeID1][nodeID2] = true;
mConnectionMap[nodeID2][nodeID1] = true;
mCostMap[nodeID1][nodeID2] = cost;
mCostMap[nodeID2][nodeID1] = cost;
}
void removeEgde(int nodeID1, int nodeID2) {
mConnectionMap[nodeID1][nodeID2] = false;
mConnectionMap[nodeID2][nodeID1] = false;
mCostMap[nodeID1][nodeID2] = 0;
mCostMap[nodeID2][nodeID1] = 0;
}
};
// グラフ
class vgraph {
public:
const int INF = 1000000;
vgraph(int nodeNum) {
mNodeNum = nodeNum;
mNodes.resize(nodeNum);
for (int i = 0; i < nodeNum; ++i) {
mNodes[i] = move(vnode(i));
}
mMinimumDists.resize(mNodeNum);
mPrevNodes.resize(mNodeNum);
}
void addEgde(int nodeID1, int nodeID2) { addEgde(nodeID1, nodeID2, 1); }
virtual void addEgde(int nodeID1, int nodeID2, int cost) = 0;
virtual void removeEgde(int nodeID1, int nodeID2) = 0;
int dfs(int start) {
vector<bool> check(mNodes.size());
fill(check, false);
int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
return dfsSub(start, check, MAX_DEPTH, 0);
}
void bfs(int start) {
vector<bool> check(mNodes.size());
fill(check, false);
int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
return bfsSub(start, check, MAX_DEPTH);
}
// ベルマンフォード法を使ってある頂点から全ての頂点への最短距離を求める
// startからたどり着ける場所に負のループが存在する場合はfalseを返す
// ダイクストラ法と違い、負のコストの辺があっても最短距離を計算できる
// O(V*E)
bool bellmanFord(int start) {
vector<int> &dist = mMinimumDists;
fill(dist, INF);
dist[start] = 0;
for (int i = 0; i < mNodeNum; ++i) {
bool update = false;
for (vnode node : mNodes) {
for (const pair<vegde, const vnode *> egde : node.getEgde()) {
int from = node.getID();
int to = egde.second->getID();
if (dist[from] == INF) {
continue;
}
if (dist[from] + egde.first.getCost() < dist[to]) {
dist[to] = dist[from] + egde.first.getCost();
update = true;
if (i == mNodeNum - 1) {
// return false;
}
}
}
}
if (!update) {
break;
}
}
return true;
}
// ダイクストラ法を使ってある頂点から全ての頂点への最短距離を求める
// 負のコストの辺があると最短距離を計算できない点に注意する
// O(E*logV)
void dijkstraSearch(int start) {
// Minimum distances for each nodes
vector<int> &dpMinDists = mMinimumDists;
fill(dpMinDists, INF);
// Result of the previous visited node
vector<int> &resultPrev = mPrevNodes;
fill(resultPrev, -1);
// Create a priority_queue for search.
typedef pair<int, int> P; // key: その頂点までの最短距離, value: 頂点の番号
priority_queue<P, vector<P>, greater<P>> pq_node;
// Mark the current node as visited and enqueue it
pq_node.push(P(0, start));
dpMinDists[start] = 0;
while (!pq_node.empty()) {
P p = pq_node.top();
pq_node.pop();
int nowDist = p.first;
int nowNodeID = p.second;
if (dpMinDists[nowNodeID] < nowDist) {
continue;
}
for (const pair<vegde, const vnode *> &egde :
mNodes[nowNodeID].getEgde()) {
const vnode *nextNode = egde.second;
int nextNodeID = nextNode->getID();
int nextNodeDist = nowDist + egde.first.getCost();
if (nextNodeDist < dpMinDists[nextNodeID]) {
dpMinDists[nextNodeID] = nextNodeDist;
resultPrev[nextNodeID] = nowNodeID;
pq_node.push(P(nextNodeDist, nextNodeID));
}
}
}
}
int calcMaxDepth() const {
pair<int, int> farestNodeData = getFarestNodeID(0);
pair<int, int> farestNodeData2 = getFarestNodeID(farestNodeData.first);
return farestNodeData2.second;
}
int getNodeNum() const { return mNodeNum; }
const vector<vnode> &getNodes() const { return mNodes; }
const vector<int> &getMinimumDists() const { return mMinimumDists; }
const vector<int> &getPrevNodes() const { return mPrevNodes; }
protected:
int dfsSub(int nodeIndex, vector<bool> &check, int MAX_DEPTH, int depth) {
check[nodeIndex] = true;
int result = 0;
// 隣接する辺を探索
if (depth < MAX_DEPTH) {
for (const auto &t : mNodes[nodeIndex].getEgde()) {
if (check[t.second->getID()]) {
// 巡回済みの辺は見ない
continue;
}
result += dfsSub(t.second->getID(), check, MAX_DEPTH, depth + 1);
}
}
// 末端での処理
result += 1; // この巡回順で末端に辿り着いた時、目的の条件を満たすなら+1する
check[nodeIndex] = false;
return result;
}
void bfsSub(int start, vector<bool> &check, int MAX_DEPTH) {
queue<pair<int, int>> target;
target.push(pair<int, int>(start, 0));
while (!target.empty()) {
pair<int, int> now = target.front();
target.pop();
// ノードに対して何かやることがあればここでやる
// mNodes[now.first].something = someData;
check[now.first] = true;
int egdeCount = 0;
if (now.second < MAX_DEPTH) {
for (const pair<vegde, const vnode *> &egde :
mNodes[now.first].getEgde()) {
if (check[egde.second->getID()]) {
// このノードはもっと少ない手順で巡回可能なので行かない
continue;
}
++egdeCount;
target.push(pair<int, int>(egde.second->getID(), now.second + 1));
}
}
if (now.second == MAX_DEPTH || egdeCount == 0) {
// 探索深さ制限またはこのノードから繋がる辺が全て巡回済み
// doSomething.
}
}
}
// 引数で受け取ったノードから最も遠いノードのidと距離を返す
// グラフにループがあると無限ループになるので注意する(つまり木専用)
pair<int, int> getFarestNodeID(int start) const {
queue<pair<int, int>> q; // nodeID, このノードまでの距離
q.push(make_pair(start, 0));
pair<int, int> finalNodeData;
vector<bool> opened(mNodeNum);
fill(opened, false);
while (!q.empty()) {
pair<int, int> nodeData = q.front();
int nodeID = nodeData.first;
int dist = nodeData.second;
if (dist > finalNodeData.second) {
finalNodeData.second = dist;
finalNodeData.first = nodeID;
}
q.pop();
for (const pair<vegde, const vnode *> egde : mNodes[nodeID].getEgde()) {
int id = egde.second->getID();
if (opened[id]) {
continue;
}
opened[id] = true;
q.push(make_pair(id, dist + egde.first.getCost()));
}
}
return finalNodeData;
}
int mNodeNum;
bool mUseMaps;
vector<vnode> mNodes;
vector<int> mMinimumDists;
vector<int> mPrevNodes;
};
// 無向グラフ UnDirected Val Graph.
class udvgraph : public vgraph {
public:
udvgraph(int nodeNum) : vgraph(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mNodes[nodeID1].addEgde(move(vegde(cost)), &mNodes[nodeID2]);
mNodes[nodeID2].addEgde(move(vegde(cost)), &mNodes[nodeID1]);
}
void removeEgde(int nodeID1, int nodeID2) {
mNodes[nodeID1].removeEgde(nodeID2);
mNodes[nodeID2].removeEgde(nodeID1);
}
};
// 隣接行列付きの無向グラフ。ワーシャルフロイドが使える。 UnDirected Val Graph
// Matrix
class udvgraph_m : public udvgraph {
public:
udvgraph_m(int nodeNum) : udvgraph(nodeNum) {
mAdjacencyMatrix = UndirectedAdjacencyMatrix(nodeNum);
}
void addEgde(int nodeID1, int nodeID2, int cost) {
udvgraph::addEgde(nodeID1, nodeID2, cost);
mAdjacencyMatrix.addEgde(nodeID1, nodeID2, cost);
}
void removeEgde(int nodeID1, int nodeID2) {
udvgraph::removeEgde(nodeID1, nodeID2);
mAdjacencyMatrix.removeEgde(nodeID1, nodeID2);
}
void warshallFloyd() { mAdjacencyMatrix.warshallFloyd(mNodeNum); }
const vector<vector<bool>> &getConnectionMap() const {
return mAdjacencyMatrix.getConnectionMap();
}
const vector<vector<int>> &getCostMap() const {
return mAdjacencyMatrix.getCostMap();
}
const vector<vector<int>> &getMinimumDistMap() const {
return mAdjacencyMatrix.getMinimumDistMap();
}
private:
UndirectedAdjacencyMatrix mAdjacencyMatrix;
};
// 有向グラフ Directed Val Graph.
class dvgraph : public vgraph {
public:
dvgraph(int nodeNum) : vgraph(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mNodes[nodeID1].addEgde(move(vegde(cost)), &mNodes[nodeID2]);
}
void removeEgde(int nodeID1, int nodeID2) {
mNodes[nodeID1].removeEgde(nodeID2);
}
// 入力のないノードのリストを返す
list<int> searchStartNodes() const {
list<int> startNodes;
unordered_map<int, int> nodesInputs; // key:ノード番号, value:インプット数
for (auto node : mNodes) {
for (auto edge : node.getEgde()) {
++nodesInputs[edge.second->getID()];
}
}
for (int i = 0; i < mNodeNum; ++i) {
if (nodesInputs.find(i) == nodesInputs.end()) {
startNodes.push_back(i);
}
}
return move(startNodes);
}
};
// 隣接行列付きの有向グラフ。ワーシャルフロイドが使える。 Directed Val Graph
// Matrix
class dvgraph_m : public dvgraph {
public:
dvgraph_m(int nodeNum) : dvgraph(nodeNum) {
mAdjacencyMatrix = DirectedAdjacencyMatrix(nodeNum);
}
void addEgde(int nodeID1, int nodeID2, int cost) {
dvgraph::addEgde(nodeID1, nodeID2, cost);
mAdjacencyMatrix.addEgde(nodeID1, nodeID2, cost);
}
void removeEgde(int nodeID1, int nodeID2) {
dvgraph::removeEgde(nodeID1, nodeID2);
mAdjacencyMatrix.removeEgde(nodeID1, nodeID2);
}
void warshallFloyd() { mAdjacencyMatrix.warshallFloyd(mNodeNum); }
const vector<vector<bool>> &getConnectionMap() const {
return mAdjacencyMatrix.getConnectionMap();
}
const vector<vector<int>> &getCostMap() const {
return mAdjacencyMatrix.getCostMap();
}
const vector<vector<int>> &getMinimumDistMap() const {
return mAdjacencyMatrix.getMinimumDistMap();
}
private:
DirectedAdjacencyMatrix mAdjacencyMatrix;
};
// 立っているビットの数を返す
static constexpr int bitcount8(unsigned char b8) {
// 8 bits 限定アルゴリズムを利用している
// c_assert( 8 == (CHAR_BIT * sizeof( b8 )) );
b8 = (unsigned char)(((b8 & 0xAA) >> 1) + (b8 & 0x55));
b8 = (unsigned char)(((b8 & 0xCC) >> 2) + (b8 & 0x33));
b8 = (unsigned char)(((b8 & 0xF0) >> 4) + (b8 & 0x0F));
return b8;
}
// 立っているビットの数を返す
static constexpr int bitcount16(unsigned short w16) {
// 16 bits 限定アルゴリズムを利用している
// c_assert( 16 == (CHAR_BIT * sizeof( w16 )) );
w16 = (unsigned short)(((w16 & 0xAAAA) >> 1) + (w16 & 0x5555));
w16 = (unsigned short)(((w16 & 0xCCCC) >> 2) + (w16 & 0x3333));
w16 = (unsigned short)(((w16 & 0xF0F0) >> 4) + (w16 & 0x0F0F));
w16 = (unsigned short)(((w16 & 0xFF00) >> 8) + (w16 & 0x00FF));
return w16;
}
// 立っているビットの数を返す
static constexpr int bitcount32(unsigned long dw32) {
// 32 bits 限定アルゴリズムを利用している
// c_assert( 32 == (CHAR_BIT * sizeof( dw32 )) );
dw32 = ((dw32 & 0xAAAAAAAA) >> 1) + (dw32 & 0x55555555);
dw32 = ((dw32 & 0xCCCCCCCC) >> 2) + (dw32 & 0x33333333);
dw32 = ((dw32 & 0xF0F0F0F0) >> 4) + (dw32 & 0x0F0F0F0F);
dw32 = ((dw32 & 0xFF00FF00) >> 8) + (dw32 & 0x00FF00FF);
dw32 = ((dw32 & 0xFFFF0000) >> 16) + (dw32 & 0x0000FFFF);
return dw32;
}
// 条件を満たす最小の要素のindexを返す
// 存在しない場合は-1を返す
// 使い方の例: int result = binarySearch<int>(A, 0, N - 1, [&](int x) { return x
// >= K; });
template <typename T>
int binarySearch(const vector<T> &vec, int beginIndex, int endIndex,
const function<bool(const T &)> &confilm) {
// 解が両端にある場合や解なしの判定のために、両端の1つ外側から始める
int lb = beginIndex - 1; // lower bound
int ub = endIndex + 1; // upper bound
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (confilm(vec[mid])) {
ub = mid;
} else {
lb = mid;
}
}
if (ub == endIndex + 1) {
// 解なし
return -1;
}
return ub;
}
// 文字列の先頭の0を削除する
string cutZeroLeft(const string &str) {
for (int i = 0; i < (int)str.length(); ++i) {
if (str[i] != '0') {
return str.substr(i);
}
}
return "";
}
// 0以上の整数を0埋めで表記する
string fillZero(ull number, int digit) {
int zeroNum = max(0, (int)(digit - to_string(number).length()));
return move(move(string(zeroNum, '0')) + move(to_string(number)));
}
// 0以上の10進数を2進数に変換する
string toBinString(ull x) {
return move(cutZeroLeft(bitset<20>(x).to_string()));
}
// 0以上の10進数を8進数に変換する
string toOctString(ull x) {
stringstream ss;
ss << std::oct << x;
return move(ss.str());
}
// 0以上の整数を16進数に変換する(a~fは小文字)
string toHexString(ull x) {
stringstream ss;
ss << std::hex << x;
return move(ss.str());
}
// 0以上の整数を任意の基数に変換する(最大36進数)(a~zは小文字)
string toBaseString(ull x, int base) {
const string table = "0123456789abcdefghijklmnopqrstuvwxyz";
assert(base >= 2 && base <= 36);
string result = "";
ull y = x;
do {
ull div = y / (ull)base;
int mod = y % (ull)base;
result = table[mod] + result;
y = div;
} while (y != 0ull);
return move(result);
}
// 任意の基数の0以上の整数を10進数に変換する
// base: 変換元の基数
ull toDecimal(string numberString, int base) {
assert(numberString.length() < 20);
assert(!numberString.empty());
return stoull(numberString, nullptr, base);
}
// double型の値を任意の少数桁数で表示する
// 指定の桁数まで0で埋める。指数表記にはならない
// precision=0を指定したときは小数点は表示しない
// 表示桁数+1桁目を四捨五入する
string sprintDoublePlane(double value, int precision) {
assert(precision >= 0);
stringstream ss;
ss << fixed << setprecision(precision) << value;
return move(ss.str());
}
class Grid {
public:
static const int INF = 1000000;
static const int MAX_H = 100;
static const int MAX_W = 100;
struct SchElem {
public:
SchElem(const Point &pos, int dist) : pos(pos), dist(dist) {}
Point pos;
int dist;
};
vector<vector<char>> mGrid;
// CTInitArray2D<bool, H, W>
int mW, mH;
Grid() = default;
Grid(int w, int h) : mW(w), mH(h) {
mGrid.resize(mH, vector<char>(mW, '\0'));
}
void input() {
for (int y = 0; y < mH; ++y) {
for (int x = 0; x < mW; ++x) {
cin >> mGrid[y][x];
}
cin.ignore();
}
}
bool isOutOfGrid(const Point &p) const {
return p.x < 0 || p.y < 0 || p.x >= mW || p.y >= mH;
}
bool canMove(int x, int y) const {
// 問題固有条件
return true;
// return mGrid[y][x] != '#';
}
bool canMove(const Point &p) const { return canMove(p.x, p.y); }
int dfs(int x, int y) {
static CTInitArray2D<bool, MAX_H, MAX_W> check(false);
check.init();
const int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
int result = 0;
stack<SchElem> target;
target.push(SchElem(Point(x, y), 0));
check.write(y, x, true);
while (!target.empty()) {
SchElem now = target.top();
target.pop();
// セルに対して何かやることがあればここでやる
// if (now.pos.x == someTargetX && now.pos.y == someTargetY) {
// result = 1;
//}
int nextCount = 0;
if (now.dist < MAX_DEPTH) {
for (int i = 0; i < 4; ++i) {
Point next = now.pos + DP4[i];
if (isOutOfGrid(next)) {
continue;
}
if (check.read(next.y, next.x)) {
// この場所はもっと少ない手順で到達可能なので行かない
continue;
}
if (!canMove(next)) {
// 移動不可のセルには移動しない
continue;
}
++nextCount;
target.push(SchElem(next, now.dist + 1));
check.write(next.y, next.x, true);
}
}
if (now.dist == MAX_DEPTH || nextCount == 0) {
// 末端での処理
// doSomething.
}
}
return result;
}
int bfs(int x, int y) {
static CTInitArray2D<bool, MAX_H, MAX_W> check(false);
check.init();
const int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
int result = MAX_DEPTH;
queue<SchElem> target;
target.push(SchElem(Point(x, y), 0));
check.write(y, x, true);
while (!target.empty()) {
SchElem now = target.front();
target.pop();
// セルに対して何かやることがあればここでやる
// if (now.pos.x == someTargetX && now.pos.y == someTargetY) {
// result = min(result, now.dist);
//}
int nextCount = 0;
if (now.dist < MAX_DEPTH) {
for (int i = 0; i < 4; ++i) {
Point next = now.pos + DP4[i];
if (isOutOfGrid(next)) {
continue;
}
if (check.read(next.y, next.x)) {
// この場所はもっと少ない手順で到達可能なので行かない
continue;
}
if (!canMove(next)) {
// 移動不可のセルには移動しない
continue;
}
++nextCount;
target.push(SchElem(next, now.dist + 1));
check.write(next.y, next.x, true);
}
}
if (now.dist == MAX_DEPTH || nextCount == 0) {
// 探索深さ制限またはこのノードから繋がる辺が全て巡回済み
// doSomething.
}
}
return result;
}
};
template <typename A> void in(A &a) {
cin >> a;
cin.ignore();
}
template <typename A, typename B> void in(A &a, B &b) {
cin >> a >> b;
cin.ignore();
}
template <typename A, typename B, typename C> void in(A &a, B &b, C &c) {
cin >> a >> b >> c;
cin.ignore();
}
template <typename A, typename B, typename C, typename D>
void in(A &a, B &b, C &c, D &d) {
cin >> a >> b >> c >> d;
cin.ignore();
}
template <typename A, typename B, typename C, typename D, typename E>
void in(A &a, B &b, C &c, D &d, E &e) {
cin >> a >> b >> c >> d >> e;
cin.ignore();
}
template <typename A, typename B, typename C, typename D, typename E,
typename F>
void in(A &a, B &b, C &c, D &d, E &e, F &f) {
cin >> a >> b >> c >> d >> e >> f;
cin.ignore();
}
template <typename A, typename B, typename C, typename D, typename E,
typename F, typename G>
void in(A &a, B &b, C &c, D &d, E &e, F &f, G &g) {
cin >> a >> b >> c >> d >> e >> f >> g;
cin.ignore();
}
template <typename A> void inr(vector<A> &a, int size) {
resize(a, size);
for (int i = 0; i < size; ++i) {
cin >> a[i];
cin.ignore();
}
}
template <typename A, typename B>
void inr(vector<A> &a, vector<B> &b, int size) {
resize(a, size);
resize(b, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i];
cin.ignore();
}
}
template <typename A, typename B, typename C>
void inr(vector<A> &a, vector<B> &b, vector<C> &c, int size) {
resize(a, size);
resize(b, size);
resize(c, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i] >> c[i];
cin.ignore();
}
}
template <typename A, typename B, typename C, typename D>
void inr(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d, int size) {
resize(a, size);
resize(b, size);
resize(c, size);
resize(d, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
cin.ignore();
}
}
template <typename A, typename B, typename C, typename D, typename E>
void inr(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d, vector<E> &e,
int size) {
resize(a, size);
resize(b, size);
resize(c, size);
resize(d, size);
resize(e, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
cin.ignore();
}
}
template <typename A> void inr(vector<vector<A>> &a, int h, int wa) {
resize(a, h, wa);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < wa; ++j) {
cin >> a[i][j];
}
cin.ignore();
}
}
template <typename A, typename B>
void inr(vector<vector<A>> &a, vector<vector<B>> &b, int h, int wa, int wb) {
resize(a, h, wa);
resize(b, h, wb);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < wa; ++j) {
cin >> a[i][j];
}
for (int j = 0; j < wb; ++j) {
cin >> b[i][j];
}
cin.ignore();
}
}
template <typename A, typename B, typename C>
void inr(vector<vector<A>> &a, vector<vector<B>> &b, vector<vector<C>> &c,
int h, int wa, int wb, int wc) {
resize(a, h, wa);
resize(b, h, wb);
resize(c, h, wc);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < wa; ++j) {
cin >> a[i][j];
}
for (int j = 0; j < wb; ++j) {
cin >> b[i][j];
}
for (int j = 0; j < wc; ++j) {
cin >> c[i][j];
}
cin.ignore();
}
}
template <typename T> void out(const T &val) { cout << val << endl; }
} // namespace ValLib
using namespace ValLib;
using namespace vmath;
int main() {
std::ios::sync_with_stdio(false);
ll N;
in(N);
ll rt = (ll)(sqrt(N) + 1e-5);
ll ans = 0;
for (ll i = 1; i <= rt; ++i) {
ll div = N / i;
if (N % (div - 1ll) == i) {
ans += div - 1ll;
}
}
out(ans);
getchar();
}
|
// #define NDEBUG
#pragma GCC optimize("O3") // 最適化レベルの変更 O0〜O3 などを指定
#pragma GCC optimize("-O3,inline,omit-frame-pointer,unroll-loops")
#pragma warning(1 : 4456) // 多重forループ内での変数の2重定義を警告にする
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <memory>
#include <chrono>
#include <functional>
#define ALL(a) (a).begin(), (a).end()
using namespace std;
namespace ValLib {
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
constexpr ull V_MOD = 1000000007ull;
constexpr int V_INT_MAX = 2147483647;
constexpr ll V_LL_MAX = 9223372036854775807ll;
constexpr ull V_ULL_MAX = 18446744073709551615ull;
template <typename Key, typename Value>
using umap = std::unordered_map<Key, Value>;
template <typename T> using uset = std::unordered_set<T>;
template <typename T> using sptr = typename std::shared_ptr<T>;
class vnode;
class vegde;
class vgraph;
template <typename T> void fill(vector<T> &vec, const T &value) {
std::fill(vec.begin(), vec.end(), value);
}
template <typename T> void fill(vector<vector<T>> &vec, const T &value) {
for (vector<T> &t : vec)
std::fill(t.begin(), t.end(), value);
}
template <typename T> void resize(vector<T> &vec, int size1) {
vec.resize(size1);
}
template <typename T> void resize(vector<T> &vec, int size1, const T &value) {
vec.resize(size1, value);
}
template <typename T>
void resize(vector<vector<T>> &vec, int size1, int size2) {
vec.resize(size1);
for (vector<T> &t : vec)
t.resize(size2);
}
template <typename T>
void resize(vector<vector<T>> &vec, int size1, int size2, const T &value) {
vec.resize(size1);
for (vector<T> &t : vec)
t.resize(size2, value);
}
template <typename T> void assign(vector<T> &vec, int size1, const T &value) {
vec.assign(size1, value);
}
template <typename T>
void assign(vector<vector<T>> &vec, int size1, int size2, const T &value) {
vec.resize(size1);
for (vector<T> &t : vec)
t.assign(size2, value);
}
template <typename T>
const typename vector<T>::const_iterator max_element(const vector<T> &vec) {
assert(!vec.empty());
return std::max_element(vec.begin(), vec.end());
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator max_element(const vector<T> &vec,
_Pr lessThan) {
assert(!vec.empty());
return std::max_element(vec.begin(), vec.end(), lessThan);
}
template <typename T> typename vector<T>::iterator min_element(vector<T> &vec) {
assert(!vec.empty());
return std::min_element(vec.begin(), vec.end());
}
template <typename T>
const typename vector<T>::const_iterator min_element(const vector<T> &vec) {
assert(!vec.empty());
return std::min_element(vec.begin(), vec.end());
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator min_element(const vector<T> &vec,
_Pr lessThan) {
assert(!vec.empty());
return std::min_element(vec.begin(), vec.end(), lessThan);
}
int accumulate(const vector<int> &vec) {
return std::accumulate(vec.begin(), vec.end(), 0);
}
template <typename _Pr> int accumulate(const vector<int> &vec, _Pr func) {
return std::accumulate(vec.begin(), vec.end(), 0, func);
}
double accumulate(const vector<double> &vec) {
return std::accumulate(vec.begin(), vec.end(), 0.0);
}
template <typename _Pr> double accumulate(const vector<double> &vec, _Pr func) {
return std::accumulate(vec.begin(), vec.end(), 0.0, func);
}
float accumulate(const vector<float> &vec) {
return std::accumulate(vec.begin(), vec.end(), 0.f);
}
template <typename _Pr> float accumulate(const vector<float> &vec, _Pr func) {
return std::accumulate(vec.begin(), vec.end(), 0.f, func);
}
template <typename T, typename _Pr>
bool all_of(const vector<T> &vec, _Pr pred) {
return std::all_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool any_of(const vector<T> &vec, _Pr pred) {
return std::any_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool none_of(const vector<T> &vec, _Pr pred) {
return std::none_of(vec.begin(), vec.end(), pred);
}
template <typename T>
const typename vector<T>::const_iterator find(const vector<T> &vec,
const T &val) {
return std::find(vec.begin(), vec.end(), val);
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator find_if(const vector<T> &vec,
_Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred);
}
template <typename T> bool contains(const vector<T> &vec, const T &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
}
template <typename T, typename _Pr>
bool contains_if(const vector<T> &vec, _Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred) != vec.end();
}
template <typename T, typename _Pr>
typename iterator_traits<
const typename vector<T>::const_iterator>::difference_type
count_if(const vector<T> &vec, _Pr pred) {
return std::count_if(vec.begin(), vec.end(), pred);
}
template <typename T> void sort(vector<T> &vec) {
std::sort(vec.begin(), vec.end());
}
template <typename T, typename _Pr> void sort(vector<T> &vec, _Pr pred) {
std::sort(vec.begin(), vec.end(), pred);
}
template <typename T> void stable_sort(vector<T> &vec) {
std::stable_sort(vec.begin(), vec.end());
}
template <typename T, typename _Pr> void stable_sort(vector<T> &vec, _Pr pred) {
std::stable_sort(vec.begin(), vec.end(), pred);
}
template <typename T, size_t N> void fill(array<T, N> &ary, const T &value) {
std::fill(ary.begin(), ary.end(), value);
}
template <typename T, size_t N, size_t M>
void fill(array<array<T, M>, N> &ary, const T &value) {
for (array<T, M> &t : ary)
std::fill(t.begin(), t.end(), value);
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator max_element(const array<T, N> &ary) {
assert(!ary.empty());
return std::max_element(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
const typename vector<T>::const_iterator max_element(const array<T, N> &ary) {
assert(!ary.empty());
return std::max_element(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator max_element(const array<T, N> &ary,
_Pr lessThan) {
assert(!ary.empty());
return std::max_element(ary.begin(), ary.end(), lessThan);
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator min_element(const array<T, N> &ary) {
assert(!ary.empty());
return std::min_element(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator min_element(const array<T, N> &ary,
_Pr lessThan) {
assert(!ary.empty());
return std::min_element(ary.begin(), ary.end(), lessThan);
}
template <size_t N> int accumulate(const array<int, N> &ary) {
return std::accumulate(ary.begin(), ary.end(), 0);
}
template <size_t N, typename _Pr>
int accumulate(const array<int, N> &ary, _Pr func) {
return std::accumulate(ary.begin(), ary.end(), 0, func);
}
template <size_t N> double accumulate(const array<double, N> &ary) {
return std::accumulate(ary.begin(), ary.end(), 0.0);
}
template <size_t N, typename _Pr>
double accumulate(const array<double, N> &ary, _Pr func) {
return std::accumulate(ary.begin(), ary.end(), 0.0, func);
}
template <size_t N> float accumulate(const array<float, N> &ary) {
return std::accumulate(ary.begin(), ary.end(), 0.f);
}
template <size_t N, typename _Pr>
float accumulate(const array<float, N> &ary, _Pr func) {
return std::accumulate(ary.begin(), ary.end(), 0.f, func);
}
template <typename T, size_t N, typename _Pr>
bool all_of(const array<T, N> &ary, _Pr pred) {
return std::all_of(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N, typename _Pr>
bool any_of(const array<T, N> &ary, _Pr pred) {
return std::any_of(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N, typename _Pr>
bool none_of(const array<T, N> &ary, _Pr pred) {
return std::none_of(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N>
const typename array<T, N>::const_iterator find(const array<T, N> &ary,
const T &val) {
return std::find(ary.begin(), ary.end(), val);
}
template <typename T, size_t N, typename _Pr>
const typename array<T, N>::const_iterator find_if(const array<T, N> &ary,
_Pr pred) {
return std::find_if(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N>
bool contains(const array<T, N> &ary, const T &val) {
return std::find(ary.begin(), ary.end(), val) != ary.end();
}
template <typename T, size_t N, typename _Pr>
bool contains_if(const array<T, N> &ary, _Pr pred) {
return std::find_if(ary.begin(), ary.end(), pred) != ary.end();
}
template <typename T, size_t N, typename _Pr>
typename iterator_traits<
const typename array<T, N>::const_iterator>::difference_type
count_if(const array<T, N> &ary, _Pr pred) {
return std::count_if(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N> void sort(array<T, N> &ary) {
std::sort(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
void sort(array<T, N> &ary, _Pr pred) {
std::sort(ary.begin(), ary.end(), pred);
}
template <typename T, size_t N> void stable_sort(array<T, N> &ary) {
std::stable_sort(ary.begin(), ary.end());
}
template <typename T, size_t N, typename _Pr>
void stable_sort(array<T, N> &ary, _Pr pred) {
std::stable_sort(ary.begin(), ary.end(), pred);
}
template <typename Key, typename Value>
bool containsKey(const umap<Key, Value> &m, const Key &key) {
return m.find(key) != m.end();
}
template <typename Key, typename Value>
bool containsValue(const umap<Key, Value> &m, const Value &val) {
for (auto it = m.begin(); it != m.end(); ++it)
if (it->second == val)
return true;
return false;
}
template <typename T>
const typename uset<T>::const_iterator find(const uset<T> &s, const T &key) {
return s.find(key);
}
template <typename T> bool contains(const uset<T> &s, const T &key) {
return s.find(key) != s.end();
}
constexpr int DX4[] = {0, -1, 0, 1};
constexpr int DY4[] = {-1, 0, 1, 0};
constexpr int DX8[] = {0, -1, -1, -1, 0, 1, 1, 1};
constexpr int DY8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
constexpr int DX5[] = {DX4[0], DX4[1], DX4[2], DX4[3], 0};
constexpr int DY5[] = {DY4[0], DY4[1], DY4[2], DY4[3], 0};
constexpr int DX9[] = {DX8[0], DX8[1], DX8[2], DX8[3], DX8[4],
DX8[5], DX8[6], DX8[7], 0};
constexpr int DY9[] = {DY8[0], DY8[1], DY8[2], DY8[3], DY8[4],
DY8[5], DY8[6], DY8[7], 0};
class Point {
public:
constexpr inline Point() : Point(-1, -1) {}
constexpr inline Point(int x, int y) : x(x), y(y) {}
static Point getManhattanDist(const Point &p1, const Point &p2) {
return move(Point(abs(p1.x - p2.x), abs(p1.y - p2.y)));
}
void setPos(const Point &pos) {
x = pos.x;
y = pos.y;
}
void setPos(int x, int y) {
this->x = x;
this->y = y;
}
Point operator+(int val) const { return move(Point(x + val, y + val)); }
Point operator-(int val) const { return move(Point(x - val, y - val)); }
Point operator*(int val) const { return move(Point(x * val, y * val)); }
Point operator/(int val) const { return move(Point(x / val, y / val)); }
Point operator+(const Point &p) const {
return move(Point(x + p.x, y + p.y));
}
Point operator-(const Point &p) const {
return move(Point(x - p.x, y - p.y));
}
Point operator*(const Point &p) const {
return move(Point(x * p.x, y * p.y));
}
Point operator/(const Point &p) const {
return move(Point(x / p.x, y / p.y));
}
void operator+=(int val) {
x += val;
y += val;
}
void operator-=(int val) {
x -= val;
y -= val;
}
void operator*=(int val) {
x *= val;
y *= val;
}
void operator/=(int val) {
x /= val;
y /= val;
}
void operator+=(const Point &p) {
x += p.x;
y += p.y;
}
void operator-=(const Point &p) {
x -= p.x;
y -= p.y;
}
void operator*=(const Point &p) {
x *= p.x;
y *= p.y;
}
void operator/=(const Point &p) {
x /= p.x;
y /= p.y;
}
bool operator==(const Point &p) const { return x == p.x && y == p.y; }
bool operator!=(const Point &p) const { return x != p.x || y != p.y; }
// bool operator<(const Point &p) const {return x * x + y * y < p.x * p.x +
// p.y * p.y;}
const Point &getPos() const { return *this; }
string to_string() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}
int x, y;
};
constexpr Point DP4[] = {Point(DX4[0], DY4[0]), Point(DX4[1], DY4[1]),
Point(DX4[2], DY4[2]), Point(DX4[3], DY4[3])};
constexpr Point DP5[] = {Point(DX5[0], DY5[0]), Point(DX5[1], DY5[1]),
Point(DX5[2], DY5[2]), Point(DX5[3], DY5[3]),
Point(DX5[4], DY5[4])};
constexpr Point DP8[] = {Point(DX8[0], DY8[0]), Point(DX8[1], DY8[1]),
Point(DX8[2], DY8[2]), Point(DX8[3], DY8[3]),
Point(DX8[4], DY8[4]), Point(DX8[5], DY8[5]),
Point(DX8[6], DY8[6]), Point(DX8[7], DY8[7])};
constexpr Point DP9[] = {Point(DX9[0], DY9[0]), Point(DX9[1], DY9[1]),
Point(DX9[2], DY9[2]), Point(DX9[3], DY9[3]),
Point(DX9[4], DY9[4]), Point(DX9[5], DY9[5]),
Point(DX9[6], DY9[6]), Point(DX9[7], DY9[7])};
// 定数時間初期化配列 (Constant Time Initializable Array)
template <typename _Vt, size_t _Sz> class CTInitArray : public array<_Vt, _Sz> {
public:
CTInitArray() = default;
CTInitArray(const _Vt &initVal) : mCurrentNum(1), mInitVal(initVal) {
std::fill(mNums.begin(), mNums.end(), 0);
}
inline void setInitVal(const _Vt &initVal) { mInitVal = initVal; }
inline void init() { ++mCurrentNum; }
inline const _Vt &read(size_t index) const {
return (mNums[index] == mCurrentNum) ? array<_Vt, _Sz>::operator[](index)
: mInitVal;
}
inline const _Vt &write(size_t index, const _Vt &val) {
mNums[index] = mCurrentNum;
return array<_Vt, _Sz>::operator[](index) = val;
}
private:
inline const _Vt &operator[](size_t index) const {
return (mNums[index] == mCurrentNum) ? array<_Vt, _Sz>::operator[](index)
: mInitVal;
}
_Vt mInitVal;
array<int, _Sz> mNums;
int mCurrentNum;
};
// 定数時間初期化配列2次元 (Constant Time Initializable Array)
template <typename _Vt, size_t _Sz1, size_t _Sz2>
class CTInitArray2D : public array<array<_Vt, _Sz2>, _Sz1> {
public:
CTInitArray2D() = default;
CTInitArray2D(const _Vt &initVal) : mCurrentNum(1), mInitVal(initVal) {
for (array<int, _Sz2> &t1 : mNums)
std::fill(t1.begin(), t1.end(), 0);
}
inline void setInitVal(const _Vt &initVal) { mInitVal = initVal; }
inline void init() { ++mCurrentNum; }
inline const _Vt &read(size_t index1, size_t index2) {
return (mNums[index1][index2] == mCurrentNum)
? array<array<_Vt, _Sz2>, _Sz1>::operator[](index1)[index2]
: mInitVal;
}
inline const _Vt &write(size_t index1, size_t index2, const _Vt &val) {
mNums[index1][index2] = mCurrentNum;
return array<array<_Vt, _Sz2>, _Sz1>::operator[](index1)[index2] = val;
}
private:
inline _Vt &operator[](size_t _Pos) {
return array<array<_Vt, _Sz2>, _Sz1>::operator[](_Pos);
} // 封印
_Vt mInitVal;
array<array<int, _Sz2>, _Sz1> mNums;
int mCurrentNum;
};
// 定数時間初期化配列3次元 (Constant Time Initializable Array)
template <typename _Vt, size_t _Sz1, size_t _Sz2, size_t _Sz3>
class CTInitArray3D : public array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1> {
public:
CTInitArray3D() = default;
CTInitArray3D(const _Vt &initVal) : mCurrentNum(1), mInitVal(initVal) {
for (array<array<int, _Sz3>, _Sz2> &t1 : mNums)
for (array<int, _Sz3> &t2 : t1)
std::fill(t2.begin(), t2.end(), 0);
}
inline void setInitVal(const _Vt &initVal) { mInitVal = initVal; }
inline void init() { ++mCurrentNum; }
inline const _Vt &read(size_t index1, size_t index2, size_t index3) {
return (mNums[index1][index2][index3] == mCurrentNum)
? array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1>::operator[](
index1)[index2][index3]
: mInitVal;
}
inline const _Vt &write(size_t index1, size_t index2, size_t index3,
const _Vt &val) {
mNums[index1][index2][index3] = mCurrentNum;
return array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1>::operator[](
index1)[index2][index3] = val;
}
private:
inline _Vt &operator[](size_t _Pos) {
return array<array<array<_Vt, _Sz3>, _Sz2>, _Sz1>::operator[](_Pos);
} // 封印
_Vt mInitVal;
array<array<array<int, _Sz3>, _Sz2>, _Sz1> mNums;
int mCurrentNum;
};
static constexpr int COMBI_MAX = 500000; // nCrのnとrの最大値
static ull gFact[COMBI_MAX + 1]; // modの世界での階乗
static ull gInv[COMBI_MAX + 1]; // modの世界での逆元
static ull gFactInv[COMBI_MAX + 1]; // modの世界での逆元の階乗
static ull gCombiInitMod = 0; // 組み合わせの計算に使用したmod値
namespace vmath {
static constexpr ull mod_add(ull a, ull b, ull mod) {
return ((a % mod) + (b % mod)) % mod;
}
static constexpr ull mod_sub(ull a, ull b, ull mod) {
// a>bだとmod-(b-a)が返る
return ((a % mod) + mod - (b % mod)) % mod;
}
static constexpr ull mod_mul(ull a, ull b, ull mod) {
return ((a % mod) * (b % mod)) % mod;
}
// 最大公約数(ユーグリッドの互除法)
static constexpr ull gcd(ull x, ull y) {
assert(x > 0ull);
assert(y > 0ull);
ull r = 0ull;
while ((r = x % y) != 0ull) {
x = y;
y = r;
}
return y;
}
// 最小公倍数
static constexpr ull lcm(ull x, ull y) {
assert(x > 0ull);
assert(y > 0ull);
return x / gcd(x, y) * y;
}
// 約数を全て求める O(√n)
static ull calcDivisors(list<ull> *divisors, ull n) {
divisors->clear();
if (n <= 0ull) {
return 0ull;
}
divisors->push_back(1ull);
if (n != 1ull) {
divisors->push_back(n);
}
for (ull i = 2ull; i * i <= n; ++i) {
if (n % i == 0ull) {
divisors->push_back(i);
if (i != n / i) {
divisors->push_back(n / i);
}
}
}
return divisors->size();
}
// 約数の個数を返す O(√n)
static ull calcDivisorNum(ull n) {
if (n <= 0ull) {
return 0ull;
}
ull count = 1ull; // for 1
if (n != 1ull) {
++count; // for n
}
// for 2~n-1
for (ull i = 2ull; i * i <= n; ++i) {
if (n % i == 0ull) {
count += 1ull;
if (i != n / i) {
count += 1ull;
}
}
}
return count;
}
// 素因数分解 O(√n)
static int calcDecompositPrime(list<ull> *primes, ull n) {
primes->clear();
if (n == 0) {
return 0ull;
}
if (n == 1) {
primes->push_back(1);
return 1ull;
}
// 割る数の初期値
ull a = 2ull;
// √n ≧ a ( n ≧ a * a ) の間ループ処理
while (n >= a * a) {
if (n % a == 0ull) {
// a で割り切れたら、a は素因数
primes->push_back(a);
// そして、割られる数を a で割る
n /= a;
} else {
// a で割り切れなかったら、 a を 1 増加させる
a++;
}
}
primes->push_back(n);
return primes->size();
}
// 素因数の数を返す O(√n)
static ull calcDecompositPrimeNum(ull n) {
if (n <= 1) {
return n;
}
ull count = 0ull;
// 割る数の初期値
ull a = 2ull;
// √n ≧ a ( n ≧ a * a ) の間ループ処理
while (n >= a * a) {
if (n % a == 0ull) {
// a で割り切れたら、a は素因数
++count;
// そして、割られる数を a で割る
n /= a;
} else {
// a で割り切れなかったら、 a を 1 増加させる
a++;
}
}
++count; // for n
return count;
}
// 階乗
static constexpr ull fact(ull x, ull mod) {
ull result = 1ull;
for (ull i = 1ull; i <= x; ++i) {
if (mod == 0ull) {
result *= i;
} else {
result = mod_mul(result, i, mod);
}
}
return result;
}
// 階乗
static constexpr ull fact(ull x) { return fact(x, 0ull); }
// 順列の個数 nPr
static constexpr ull permutation(ull n, ull r, ull mod) {
assert(n >= r);
if (n == 0ull || r == 0ull) {
return 0ull;
}
// return fact(n) / fact(n - r);
ull result = 1ull;
for (ull i = n; i > n - r; --i) {
if (mod == 0ull) {
result *= i;
} else {
result = mod_mul(result, i, mod);
}
}
return result;
}
// 順列の個数 nPr
static constexpr ull permutation(ull n, ull r) {
return permutation(n, r, 0ull);
}
// 組み合わせテーブルを作る
static void initCombination(ull mod) {
gFact[0] = gFact[1] = 1;
gFactInv[0] = gFactInv[1] = 1;
gInv[1] = 1;
for (int i = 2; i <= COMBI_MAX; i++) {
gFact[i] = gFact[i - 1] * i % mod;
gInv[i] = mod - gInv[mod % i] * (mod / i) % mod;
gFactInv[i] = gFactInv[i - 1] * gInv[i] % mod;
}
gCombiInitMod = mod;
}
static void initCombination() { initCombination(V_MOD); }
// 組み合わせの数を計算
static long long combination(ull n, ull k) {
assert(gCombiInitMod > 0 && "先にinitCombinationを呼び出して");
assert(n <= (ull)COMBI_MAX);
assert(k <= (ull)COMBI_MAX);
if (n < k)
return 0;
return (gFact[n] * ((gFactInv[k] * gFactInv[n - k]) % V_MOD)) % V_MOD;
}
// 重複組合せ nHr = n+r-1Cr
// 使いどころ:n人にr個を配るとき、同じ人に何個配っても良い場合とか
// 4人に5個の◯を配るときa=2,b=0,c=2,d=1のとき、◯◯||◯◯|◯みたいになる。
// これは◯と|を混ぜた組み合わせで、◯の数がn,棒の数はr-1だから全体でn+r-1
// (n-r)で割ったものが順列n+r-1Prで、それを更にrで割っているからnHr = n+r-1Cr
static ull repeatedCombination(ull n, ull r) {
return combination(n + r - 1, r);
}
// xのN乗を求める(バイナリ法) O(logN)
static constexpr ull intPow(ull x, ull n, ull mod) {
assert(x >= 0ull);
assert(n >= 0ull);
if (x == 0ull) {
if (n == 0ull) {
return 1ull;
} else {
return 0ull;
}
}
ull result = 1ull;
ull z = x;
while (n > 0ull) {
if (n & 1ull) {
if (mod > 0ull) {
result = mod_mul(result, z, mod);
} else {
result *= z;
}
}
if (mod > 0ull) {
z = mod_mul(z, z, mod);
} else {
z *= z;
}
n >>= 1ull;
}
return result;
}
// xのN乗を求める(バイナリ法) O(logN)
static constexpr ull intPow(ull x, ull n) { return intPow(x, n, 0ull); }
// xのN桁目の数値を得る
static constexpr ull getNDigitNumber(ull x, ull n) {
assert(n > 0);
assert(n <= 20);
return (x / intPow(10ull, n - 1ull)) % 10;
}
}; // namespace vmath
class vegde {
public:
vegde() : vegde(-1) {}
vegde(int cost) : mCost(cost) {}
int getCost() const { return mCost; }
private:
int mCost;
};
class vnode {
public:
vnode() : vnode(-1) {}
vnode(int id) : mID(id) {}
void addEgde(const vegde &egde, const vnode *node) {
mEgdeList.emplace_back(egde, node);
}
void removeEgde(int nodeID) {
auto itrNewEnd =
std::remove_if(mEgdeList.begin(), mEgdeList.end(),
[=](const pair<vegde, const vnode *> &p) -> bool {
return (p.second->getID() == nodeID);
});
mEgdeList.erase(itrNewEnd, mEgdeList.end());
}
int getID() const { return mID; }
const list<pair<vegde, const vnode *>> &getEgde() const { return mEgdeList; }
private:
list<pair<vegde, const vnode *>> mEgdeList;
int mID;
};
class AdjacencyMatrix {
public:
AdjacencyMatrix() = default;
AdjacencyMatrix(int nodeNum) {
resize(mConnectionMap, nodeNum, nodeNum);
resize(mCostMap, nodeNum, nodeNum);
resize(mMinimumDistMap, nodeNum, nodeNum);
}
// virtual void addEdge(int nodeID1, int nodeID2, int cost) = 0;
// virtual void removeEgde(int nodeID1, int nodeID2) = 0;
void warshallFloyd(int nodeNum) {
for (int k = 0; k < nodeNum; ++k) {
for (int i = 0; i < nodeNum; ++i) {
for (int j = 0; j < nodeNum; ++j) {
if (mConnectionMap[i][j]) {
mMinimumDistMap[i][j] = mCostMap[i][j];
} else {
mMinimumDistMap[i][j] = 99999999;
}
}
}
}
for (int k = 0; k < nodeNum; ++k) {
for (int i = 0; i < nodeNum; ++i) {
for (int j = 0; j < nodeNum; ++j) {
mMinimumDistMap[i][j] =
min(mMinimumDistMap[i][j],
mMinimumDistMap[i][k] + mMinimumDistMap[k][j]);
}
}
}
// for (int i = 0; i < mNodeNum; ++i) {
// for (int j = 0; j < mNodeNum; ++j) {
// cerr << mMinimumDistMap[i][j] << ", ";
// }
// cerr << endl;
// }
}
const vector<vector<bool>> &getConnectionMap() const {
return mConnectionMap;
}
const vector<vector<int>> &getCostMap() const { return mCostMap; }
const vector<vector<int>> &getMinimumDistMap() const {
return mMinimumDistMap;
}
protected:
vector<vector<bool>> mConnectionMap;
vector<vector<int>> mCostMap;
vector<vector<int>> mMinimumDistMap;
};
class DirectedAdjacencyMatrix : public AdjacencyMatrix {
public:
DirectedAdjacencyMatrix() = default;
DirectedAdjacencyMatrix(int nodeNum) : AdjacencyMatrix(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mConnectionMap[nodeID1][nodeID2] = true;
mCostMap[nodeID1][nodeID2] = cost;
}
void removeEgde(int nodeID1, int nodeID2) {
mConnectionMap[nodeID1][nodeID2] = false;
mCostMap[nodeID1][nodeID2] = 0;
}
};
class UndirectedAdjacencyMatrix : public AdjacencyMatrix {
public:
UndirectedAdjacencyMatrix() = default;
UndirectedAdjacencyMatrix(int nodeNum) : AdjacencyMatrix(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mConnectionMap[nodeID1][nodeID2] = true;
mConnectionMap[nodeID2][nodeID1] = true;
mCostMap[nodeID1][nodeID2] = cost;
mCostMap[nodeID2][nodeID1] = cost;
}
void removeEgde(int nodeID1, int nodeID2) {
mConnectionMap[nodeID1][nodeID2] = false;
mConnectionMap[nodeID2][nodeID1] = false;
mCostMap[nodeID1][nodeID2] = 0;
mCostMap[nodeID2][nodeID1] = 0;
}
};
// グラフ
class vgraph {
public:
const int INF = 1000000;
vgraph(int nodeNum) {
mNodeNum = nodeNum;
mNodes.resize(nodeNum);
for (int i = 0; i < nodeNum; ++i) {
mNodes[i] = move(vnode(i));
}
mMinimumDists.resize(mNodeNum);
mPrevNodes.resize(mNodeNum);
}
void addEgde(int nodeID1, int nodeID2) { addEgde(nodeID1, nodeID2, 1); }
virtual void addEgde(int nodeID1, int nodeID2, int cost) = 0;
virtual void removeEgde(int nodeID1, int nodeID2) = 0;
int dfs(int start) {
vector<bool> check(mNodes.size());
fill(check, false);
int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
return dfsSub(start, check, MAX_DEPTH, 0);
}
void bfs(int start) {
vector<bool> check(mNodes.size());
fill(check, false);
int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
return bfsSub(start, check, MAX_DEPTH);
}
// ベルマンフォード法を使ってある頂点から全ての頂点への最短距離を求める
// startからたどり着ける場所に負のループが存在する場合はfalseを返す
// ダイクストラ法と違い、負のコストの辺があっても最短距離を計算できる
// O(V*E)
bool bellmanFord(int start) {
vector<int> &dist = mMinimumDists;
fill(dist, INF);
dist[start] = 0;
for (int i = 0; i < mNodeNum; ++i) {
bool update = false;
for (vnode node : mNodes) {
for (const pair<vegde, const vnode *> egde : node.getEgde()) {
int from = node.getID();
int to = egde.second->getID();
if (dist[from] == INF) {
continue;
}
if (dist[from] + egde.first.getCost() < dist[to]) {
dist[to] = dist[from] + egde.first.getCost();
update = true;
if (i == mNodeNum - 1) {
// return false;
}
}
}
}
if (!update) {
break;
}
}
return true;
}
// ダイクストラ法を使ってある頂点から全ての頂点への最短距離を求める
// 負のコストの辺があると最短距離を計算できない点に注意する
// O(E*logV)
void dijkstraSearch(int start) {
// Minimum distances for each nodes
vector<int> &dpMinDists = mMinimumDists;
fill(dpMinDists, INF);
// Result of the previous visited node
vector<int> &resultPrev = mPrevNodes;
fill(resultPrev, -1);
// Create a priority_queue for search.
typedef pair<int, int> P; // key: その頂点までの最短距離, value: 頂点の番号
priority_queue<P, vector<P>, greater<P>> pq_node;
// Mark the current node as visited and enqueue it
pq_node.push(P(0, start));
dpMinDists[start] = 0;
while (!pq_node.empty()) {
P p = pq_node.top();
pq_node.pop();
int nowDist = p.first;
int nowNodeID = p.second;
if (dpMinDists[nowNodeID] < nowDist) {
continue;
}
for (const pair<vegde, const vnode *> &egde :
mNodes[nowNodeID].getEgde()) {
const vnode *nextNode = egde.second;
int nextNodeID = nextNode->getID();
int nextNodeDist = nowDist + egde.first.getCost();
if (nextNodeDist < dpMinDists[nextNodeID]) {
dpMinDists[nextNodeID] = nextNodeDist;
resultPrev[nextNodeID] = nowNodeID;
pq_node.push(P(nextNodeDist, nextNodeID));
}
}
}
}
int calcMaxDepth() const {
pair<int, int> farestNodeData = getFarestNodeID(0);
pair<int, int> farestNodeData2 = getFarestNodeID(farestNodeData.first);
return farestNodeData2.second;
}
int getNodeNum() const { return mNodeNum; }
const vector<vnode> &getNodes() const { return mNodes; }
const vector<int> &getMinimumDists() const { return mMinimumDists; }
const vector<int> &getPrevNodes() const { return mPrevNodes; }
protected:
int dfsSub(int nodeIndex, vector<bool> &check, int MAX_DEPTH, int depth) {
check[nodeIndex] = true;
int result = 0;
// 隣接する辺を探索
if (depth < MAX_DEPTH) {
for (const auto &t : mNodes[nodeIndex].getEgde()) {
if (check[t.second->getID()]) {
// 巡回済みの辺は見ない
continue;
}
result += dfsSub(t.second->getID(), check, MAX_DEPTH, depth + 1);
}
}
// 末端での処理
result += 1; // この巡回順で末端に辿り着いた時、目的の条件を満たすなら+1する
check[nodeIndex] = false;
return result;
}
void bfsSub(int start, vector<bool> &check, int MAX_DEPTH) {
queue<pair<int, int>> target;
target.push(pair<int, int>(start, 0));
while (!target.empty()) {
pair<int, int> now = target.front();
target.pop();
// ノードに対して何かやることがあればここでやる
// mNodes[now.first].something = someData;
check[now.first] = true;
int egdeCount = 0;
if (now.second < MAX_DEPTH) {
for (const pair<vegde, const vnode *> &egde :
mNodes[now.first].getEgde()) {
if (check[egde.second->getID()]) {
// このノードはもっと少ない手順で巡回可能なので行かない
continue;
}
++egdeCount;
target.push(pair<int, int>(egde.second->getID(), now.second + 1));
}
}
if (now.second == MAX_DEPTH || egdeCount == 0) {
// 探索深さ制限またはこのノードから繋がる辺が全て巡回済み
// doSomething.
}
}
}
// 引数で受け取ったノードから最も遠いノードのidと距離を返す
// グラフにループがあると無限ループになるので注意する(つまり木専用)
pair<int, int> getFarestNodeID(int start) const {
queue<pair<int, int>> q; // nodeID, このノードまでの距離
q.push(make_pair(start, 0));
pair<int, int> finalNodeData;
vector<bool> opened(mNodeNum);
fill(opened, false);
while (!q.empty()) {
pair<int, int> nodeData = q.front();
int nodeID = nodeData.first;
int dist = nodeData.second;
if (dist > finalNodeData.second) {
finalNodeData.second = dist;
finalNodeData.first = nodeID;
}
q.pop();
for (const pair<vegde, const vnode *> egde : mNodes[nodeID].getEgde()) {
int id = egde.second->getID();
if (opened[id]) {
continue;
}
opened[id] = true;
q.push(make_pair(id, dist + egde.first.getCost()));
}
}
return finalNodeData;
}
int mNodeNum;
bool mUseMaps;
vector<vnode> mNodes;
vector<int> mMinimumDists;
vector<int> mPrevNodes;
};
// 無向グラフ UnDirected Val Graph.
class udvgraph : public vgraph {
public:
udvgraph(int nodeNum) : vgraph(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mNodes[nodeID1].addEgde(move(vegde(cost)), &mNodes[nodeID2]);
mNodes[nodeID2].addEgde(move(vegde(cost)), &mNodes[nodeID1]);
}
void removeEgde(int nodeID1, int nodeID2) {
mNodes[nodeID1].removeEgde(nodeID2);
mNodes[nodeID2].removeEgde(nodeID1);
}
};
// 隣接行列付きの無向グラフ。ワーシャルフロイドが使える。 UnDirected Val Graph
// Matrix
class udvgraph_m : public udvgraph {
public:
udvgraph_m(int nodeNum) : udvgraph(nodeNum) {
mAdjacencyMatrix = UndirectedAdjacencyMatrix(nodeNum);
}
void addEgde(int nodeID1, int nodeID2, int cost) {
udvgraph::addEgde(nodeID1, nodeID2, cost);
mAdjacencyMatrix.addEgde(nodeID1, nodeID2, cost);
}
void removeEgde(int nodeID1, int nodeID2) {
udvgraph::removeEgde(nodeID1, nodeID2);
mAdjacencyMatrix.removeEgde(nodeID1, nodeID2);
}
void warshallFloyd() { mAdjacencyMatrix.warshallFloyd(mNodeNum); }
const vector<vector<bool>> &getConnectionMap() const {
return mAdjacencyMatrix.getConnectionMap();
}
const vector<vector<int>> &getCostMap() const {
return mAdjacencyMatrix.getCostMap();
}
const vector<vector<int>> &getMinimumDistMap() const {
return mAdjacencyMatrix.getMinimumDistMap();
}
private:
UndirectedAdjacencyMatrix mAdjacencyMatrix;
};
// 有向グラフ Directed Val Graph.
class dvgraph : public vgraph {
public:
dvgraph(int nodeNum) : vgraph(nodeNum) {}
void addEgde(int nodeID1, int nodeID2, int cost) {
mNodes[nodeID1].addEgde(move(vegde(cost)), &mNodes[nodeID2]);
}
void removeEgde(int nodeID1, int nodeID2) {
mNodes[nodeID1].removeEgde(nodeID2);
}
// 入力のないノードのリストを返す
list<int> searchStartNodes() const {
list<int> startNodes;
unordered_map<int, int> nodesInputs; // key:ノード番号, value:インプット数
for (auto node : mNodes) {
for (auto edge : node.getEgde()) {
++nodesInputs[edge.second->getID()];
}
}
for (int i = 0; i < mNodeNum; ++i) {
if (nodesInputs.find(i) == nodesInputs.end()) {
startNodes.push_back(i);
}
}
return move(startNodes);
}
};
// 隣接行列付きの有向グラフ。ワーシャルフロイドが使える。 Directed Val Graph
// Matrix
class dvgraph_m : public dvgraph {
public:
dvgraph_m(int nodeNum) : dvgraph(nodeNum) {
mAdjacencyMatrix = DirectedAdjacencyMatrix(nodeNum);
}
void addEgde(int nodeID1, int nodeID2, int cost) {
dvgraph::addEgde(nodeID1, nodeID2, cost);
mAdjacencyMatrix.addEgde(nodeID1, nodeID2, cost);
}
void removeEgde(int nodeID1, int nodeID2) {
dvgraph::removeEgde(nodeID1, nodeID2);
mAdjacencyMatrix.removeEgde(nodeID1, nodeID2);
}
void warshallFloyd() { mAdjacencyMatrix.warshallFloyd(mNodeNum); }
const vector<vector<bool>> &getConnectionMap() const {
return mAdjacencyMatrix.getConnectionMap();
}
const vector<vector<int>> &getCostMap() const {
return mAdjacencyMatrix.getCostMap();
}
const vector<vector<int>> &getMinimumDistMap() const {
return mAdjacencyMatrix.getMinimumDistMap();
}
private:
DirectedAdjacencyMatrix mAdjacencyMatrix;
};
// 立っているビットの数を返す
static constexpr int bitcount8(unsigned char b8) {
// 8 bits 限定アルゴリズムを利用している
// c_assert( 8 == (CHAR_BIT * sizeof( b8 )) );
b8 = (unsigned char)(((b8 & 0xAA) >> 1) + (b8 & 0x55));
b8 = (unsigned char)(((b8 & 0xCC) >> 2) + (b8 & 0x33));
b8 = (unsigned char)(((b8 & 0xF0) >> 4) + (b8 & 0x0F));
return b8;
}
// 立っているビットの数を返す
static constexpr int bitcount16(unsigned short w16) {
// 16 bits 限定アルゴリズムを利用している
// c_assert( 16 == (CHAR_BIT * sizeof( w16 )) );
w16 = (unsigned short)(((w16 & 0xAAAA) >> 1) + (w16 & 0x5555));
w16 = (unsigned short)(((w16 & 0xCCCC) >> 2) + (w16 & 0x3333));
w16 = (unsigned short)(((w16 & 0xF0F0) >> 4) + (w16 & 0x0F0F));
w16 = (unsigned short)(((w16 & 0xFF00) >> 8) + (w16 & 0x00FF));
return w16;
}
// 立っているビットの数を返す
static constexpr int bitcount32(unsigned long dw32) {
// 32 bits 限定アルゴリズムを利用している
// c_assert( 32 == (CHAR_BIT * sizeof( dw32 )) );
dw32 = ((dw32 & 0xAAAAAAAA) >> 1) + (dw32 & 0x55555555);
dw32 = ((dw32 & 0xCCCCCCCC) >> 2) + (dw32 & 0x33333333);
dw32 = ((dw32 & 0xF0F0F0F0) >> 4) + (dw32 & 0x0F0F0F0F);
dw32 = ((dw32 & 0xFF00FF00) >> 8) + (dw32 & 0x00FF00FF);
dw32 = ((dw32 & 0xFFFF0000) >> 16) + (dw32 & 0x0000FFFF);
return dw32;
}
// 条件を満たす最小の要素のindexを返す
// 存在しない場合は-1を返す
// 使い方の例: int result = binarySearch<int>(A, 0, N - 1, [&](int x) { return x
// >= K; });
template <typename T>
int binarySearch(const vector<T> &vec, int beginIndex, int endIndex,
const function<bool(const T &)> &confilm) {
// 解が両端にある場合や解なしの判定のために、両端の1つ外側から始める
int lb = beginIndex - 1; // lower bound
int ub = endIndex + 1; // upper bound
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
if (confilm(vec[mid])) {
ub = mid;
} else {
lb = mid;
}
}
if (ub == endIndex + 1) {
// 解なし
return -1;
}
return ub;
}
// 文字列の先頭の0を削除する
string cutZeroLeft(const string &str) {
for (int i = 0; i < (int)str.length(); ++i) {
if (str[i] != '0') {
return str.substr(i);
}
}
return "";
}
// 0以上の整数を0埋めで表記する
string fillZero(ull number, int digit) {
int zeroNum = max(0, (int)(digit - to_string(number).length()));
return move(move(string(zeroNum, '0')) + move(to_string(number)));
}
// 0以上の10進数を2進数に変換する
string toBinString(ull x) {
return move(cutZeroLeft(bitset<20>(x).to_string()));
}
// 0以上の10進数を8進数に変換する
string toOctString(ull x) {
stringstream ss;
ss << std::oct << x;
return move(ss.str());
}
// 0以上の整数を16進数に変換する(a~fは小文字)
string toHexString(ull x) {
stringstream ss;
ss << std::hex << x;
return move(ss.str());
}
// 0以上の整数を任意の基数に変換する(最大36進数)(a~zは小文字)
string toBaseString(ull x, int base) {
const string table = "0123456789abcdefghijklmnopqrstuvwxyz";
assert(base >= 2 && base <= 36);
string result = "";
ull y = x;
do {
ull div = y / (ull)base;
int mod = y % (ull)base;
result = table[mod] + result;
y = div;
} while (y != 0ull);
return move(result);
}
// 任意の基数の0以上の整数を10進数に変換する
// base: 変換元の基数
ull toDecimal(string numberString, int base) {
assert(numberString.length() < 20);
assert(!numberString.empty());
return stoull(numberString, nullptr, base);
}
// double型の値を任意の少数桁数で表示する
// 指定の桁数まで0で埋める。指数表記にはならない
// precision=0を指定したときは小数点は表示しない
// 表示桁数+1桁目を四捨五入する
string sprintDoublePlane(double value, int precision) {
assert(precision >= 0);
stringstream ss;
ss << fixed << setprecision(precision) << value;
return move(ss.str());
}
class Grid {
public:
static const int INF = 1000000;
static const int MAX_H = 100;
static const int MAX_W = 100;
struct SchElem {
public:
SchElem(const Point &pos, int dist) : pos(pos), dist(dist) {}
Point pos;
int dist;
};
vector<vector<char>> mGrid;
// CTInitArray2D<bool, H, W>
int mW, mH;
Grid() = default;
Grid(int w, int h) : mW(w), mH(h) {
mGrid.resize(mH, vector<char>(mW, '\0'));
}
void input() {
for (int y = 0; y < mH; ++y) {
for (int x = 0; x < mW; ++x) {
cin >> mGrid[y][x];
}
cin.ignore();
}
}
bool isOutOfGrid(const Point &p) const {
return p.x < 0 || p.y < 0 || p.x >= mW || p.y >= mH;
}
bool canMove(int x, int y) const {
// 問題固有条件
return true;
// return mGrid[y][x] != '#';
}
bool canMove(const Point &p) const { return canMove(p.x, p.y); }
int dfs(int x, int y) {
static CTInitArray2D<bool, MAX_H, MAX_W> check(false);
check.init();
const int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
int result = 0;
stack<SchElem> target;
target.push(SchElem(Point(x, y), 0));
check.write(y, x, true);
while (!target.empty()) {
SchElem now = target.top();
target.pop();
// セルに対して何かやることがあればここでやる
// if (now.pos.x == someTargetX && now.pos.y == someTargetY) {
// result = 1;
//}
int nextCount = 0;
if (now.dist < MAX_DEPTH) {
for (int i = 0; i < 4; ++i) {
Point next = now.pos + DP4[i];
if (isOutOfGrid(next)) {
continue;
}
if (check.read(next.y, next.x)) {
// この場所はもっと少ない手順で到達可能なので行かない
continue;
}
if (!canMove(next)) {
// 移動不可のセルには移動しない
continue;
}
++nextCount;
target.push(SchElem(next, now.dist + 1));
check.write(next.y, next.x, true);
}
}
if (now.dist == MAX_DEPTH || nextCount == 0) {
// 末端での処理
// doSomething.
}
}
return result;
}
int bfs(int x, int y) {
static CTInitArray2D<bool, MAX_H, MAX_W> check(false);
check.init();
const int MAX_DEPTH = INF; // 探索の深さ制限があれば定義する
int result = MAX_DEPTH;
queue<SchElem> target;
target.push(SchElem(Point(x, y), 0));
check.write(y, x, true);
while (!target.empty()) {
SchElem now = target.front();
target.pop();
// セルに対して何かやることがあればここでやる
// if (now.pos.x == someTargetX && now.pos.y == someTargetY) {
// result = min(result, now.dist);
//}
int nextCount = 0;
if (now.dist < MAX_DEPTH) {
for (int i = 0; i < 4; ++i) {
Point next = now.pos + DP4[i];
if (isOutOfGrid(next)) {
continue;
}
if (check.read(next.y, next.x)) {
// この場所はもっと少ない手順で到達可能なので行かない
continue;
}
if (!canMove(next)) {
// 移動不可のセルには移動しない
continue;
}
++nextCount;
target.push(SchElem(next, now.dist + 1));
check.write(next.y, next.x, true);
}
}
if (now.dist == MAX_DEPTH || nextCount == 0) {
// 探索深さ制限またはこのノードから繋がる辺が全て巡回済み
// doSomething.
}
}
return result;
}
};
template <typename A> void in(A &a) {
cin >> a;
cin.ignore();
}
template <typename A, typename B> void in(A &a, B &b) {
cin >> a >> b;
cin.ignore();
}
template <typename A, typename B, typename C> void in(A &a, B &b, C &c) {
cin >> a >> b >> c;
cin.ignore();
}
template <typename A, typename B, typename C, typename D>
void in(A &a, B &b, C &c, D &d) {
cin >> a >> b >> c >> d;
cin.ignore();
}
template <typename A, typename B, typename C, typename D, typename E>
void in(A &a, B &b, C &c, D &d, E &e) {
cin >> a >> b >> c >> d >> e;
cin.ignore();
}
template <typename A, typename B, typename C, typename D, typename E,
typename F>
void in(A &a, B &b, C &c, D &d, E &e, F &f) {
cin >> a >> b >> c >> d >> e >> f;
cin.ignore();
}
template <typename A, typename B, typename C, typename D, typename E,
typename F, typename G>
void in(A &a, B &b, C &c, D &d, E &e, F &f, G &g) {
cin >> a >> b >> c >> d >> e >> f >> g;
cin.ignore();
}
template <typename A> void inr(vector<A> &a, int size) {
resize(a, size);
for (int i = 0; i < size; ++i) {
cin >> a[i];
cin.ignore();
}
}
template <typename A, typename B>
void inr(vector<A> &a, vector<B> &b, int size) {
resize(a, size);
resize(b, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i];
cin.ignore();
}
}
template <typename A, typename B, typename C>
void inr(vector<A> &a, vector<B> &b, vector<C> &c, int size) {
resize(a, size);
resize(b, size);
resize(c, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i] >> c[i];
cin.ignore();
}
}
template <typename A, typename B, typename C, typename D>
void inr(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d, int size) {
resize(a, size);
resize(b, size);
resize(c, size);
resize(d, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
cin.ignore();
}
}
template <typename A, typename B, typename C, typename D, typename E>
void inr(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d, vector<E> &e,
int size) {
resize(a, size);
resize(b, size);
resize(c, size);
resize(d, size);
resize(e, size);
for (int i = 0; i < size; ++i) {
cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
cin.ignore();
}
}
template <typename A> void inr(vector<vector<A>> &a, int h, int wa) {
resize(a, h, wa);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < wa; ++j) {
cin >> a[i][j];
}
cin.ignore();
}
}
template <typename A, typename B>
void inr(vector<vector<A>> &a, vector<vector<B>> &b, int h, int wa, int wb) {
resize(a, h, wa);
resize(b, h, wb);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < wa; ++j) {
cin >> a[i][j];
}
for (int j = 0; j < wb; ++j) {
cin >> b[i][j];
}
cin.ignore();
}
}
template <typename A, typename B, typename C>
void inr(vector<vector<A>> &a, vector<vector<B>> &b, vector<vector<C>> &c,
int h, int wa, int wb, int wc) {
resize(a, h, wa);
resize(b, h, wb);
resize(c, h, wc);
for (int i = 0; i < h; ++i) {
for (int j = 0; j < wa; ++j) {
cin >> a[i][j];
}
for (int j = 0; j < wb; ++j) {
cin >> b[i][j];
}
for (int j = 0; j < wc; ++j) {
cin >> c[i][j];
}
cin.ignore();
}
}
template <typename T> void out(const T &val) { cout << val << endl; }
} // namespace ValLib
using namespace ValLib;
using namespace vmath;
int main() {
std::ios::sync_with_stdio(false);
ll N;
in(N);
if (N == 1) {
out(0);
return 0;
}
ll rt = (ll)(sqrt(N) + 1e-5);
ll ans = 0;
for (ll i = 1; i <= rt; ++i) {
ll div = N / i;
if (N % (div - 1ll) == i) {
ans += div - 1ll;
}
}
out(ans);
getchar();
}
| insert | 1,656 | 1,656 | 1,656 | 1,661 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int N;
int ans = 0;
signed main(void) {
cin >> N;
for (int p = 1; p * p <= N; p++) {
if (N % p == 0) { // 約数
int m_plus_one = N / p;
int m = m_plus_one - 1;
if (N % m == N / m)
ans += m;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int N;
int ans = 0;
signed main(void) {
cin >> N;
for (int p = 1; p * p <= N; p++) {
if (N % p == 0) { // 約数
int m_plus_one = N / p;
int m = m_plus_one - 1;
if (m == 0)
continue;
if (N % m == N / m)
ans += m;
}
}
cout << ans << endl;
return 0;
} | insert | 31 | 31 | 31 | 33 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, ans = 0;
cin >> N;
for (int p = 1; p * (p + 1) < N; p++) {
if (N % p == 0)
ans += N / p - 1;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, ans = 0;
cin >> N;
for (int p = 1; (N - p) / p > p; p++) {
if (N % p == 0)
ans += N / p - 1;
}
cout << ans << endl;
} | replace | 6 | 7 | 6 | 7 | TLE | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
#define foreach(it, ar) \
for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF
#define debug(x) cout << #x << ": " << x << endl
#define arr1d(a, n) \
cout << #a << " : "; \
fr(_, 1, n) cout << a[_] << ' '; \
cout << endl;
#define arr1d0(a, n) \
cout << #a << " : "; \
rep(_, n) cout << a[_] << ' '; \
cout << endl;
#define arr2d(a, n, m) \
cout << #a << " :" << endl; \
fr(_, 1, n) { \
fr(__, 1, m) cout << a[_][__] << ' '; \
cout << endl; \
}
#define arr2d0(a, n, m) \
cout << #a << " :" << endl; \
rep(_, n) { \
rep(__, m) cout << a[_][__] << ' '; \
cout << endl; \
}
/*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */
/*IIT Roorkee = <3 */
#define ull unsigned long long
#define ll long long
#define ld double
#define ui unsigned int
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define y0 yyyyyy0
auto clk = clock();
#define y1 yyyyyy1
#define BIT(n) (1 << (n))
#define SQR(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define LSOne(S) (S) & (-S)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;
template <typename T> inline T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }
template <typename T> string toStr(T x) {
stringstream st;
st << x;
string s;
st >> s;
return s;
}
template <class T> void splitStr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
inline int two(int n) { return 1 << n; }
inline int isOnBit(int n, int b) { return (n >> b) & 1; }
inline void onBit(int &n, int b) { n |= two(b); }
inline void offBit(int &n, int b) { n &= ~two(b); }
inline int lastBit(int n) { return n & (-n); }
inline int cntBit(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
#define INP "test.inp"
#define OUT "test.out"
#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 100000
#define MOD 1000000007
#define dec decr
// END OF COMPETITVE PROGRAMMING TEMPLATE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll modexp(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed;
cout << setprecision(9);
ll n;
cin >> n;
if (n == 1) {
cout << "0";
return 0;
}
ll x = (ll)(sqrt(n));
x++;
ll ans = 0;
for (ll i = 1; i <= x; i++) {
ll z = n - i;
if (z % i == 0) {
ll k = z / i;
if (n / k == n % k) {
ans += k;
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (long long i = (n)-1; i >= 0; i--)
#define foreach(it, ar) \
for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)
#define fill(ar, val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF
#define debug(x) cout << #x << ": " << x << endl
#define arr1d(a, n) \
cout << #a << " : "; \
fr(_, 1, n) cout << a[_] << ' '; \
cout << endl;
#define arr1d0(a, n) \
cout << #a << " : "; \
rep(_, n) cout << a[_] << ' '; \
cout << endl;
#define arr2d(a, n, m) \
cout << #a << " :" << endl; \
fr(_, 1, n) { \
fr(__, 1, m) cout << a[_][__] << ' '; \
cout << endl; \
}
#define arr2d0(a, n, m) \
cout << #a << " :" << endl; \
rep(_, n) { \
rep(__, m) cout << a[_][__] << ' '; \
cout << endl; \
}
/*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */
/*IIT Roorkee = <3 */
#define ull unsigned long long
#define ll long long
#define ld double
#define ui unsigned int
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define y0 yyyyyy0
auto clk = clock();
#define y1 yyyyyy1
#define BIT(n) (1 << (n))
#define SQR(x) ((x) * (x))
#define CUBE(x) ((x) * (x) * (x))
#define LSOne(S) (S) & (-S)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;
template <typename T> inline T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }
template <typename T> string toStr(T x) {
stringstream st;
st << x;
string s;
st >> s;
return s;
}
template <class T> void splitStr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
inline int two(int n) { return 1 << n; }
inline int isOnBit(int n, int b) { return (n >> b) & 1; }
inline void onBit(int &n, int b) { n |= two(b); }
inline void offBit(int &n, int b) { n &= ~two(b); }
inline int lastBit(int n) { return n & (-n); }
inline int cntBit(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
#define INP "test.inp"
#define OUT "test.out"
#define PI 3.1415926535897932385
#define INF 1000111222
#define EPS 1e-7
#define MAXN 100000
#define MOD 1000000007
#define dec decr
// END OF COMPETITVE PROGRAMMING TEMPLATE
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll modexp(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed;
cout << setprecision(9);
ll n;
cin >> n;
if (n == 1) {
cout << "0";
return 0;
}
ll x = (ll)(sqrt(n));
x++;
ll ans = 0;
for (ll i = 1; i <= x; i++) {
ll z = n - i;
if (z % i == 0) {
ll k = z / i;
if (k != 0 && n / k == n % k) {
ans += k;
}
}
}
cout << ans;
return 0;
} | replace | 143 | 144 | 143 | 144 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) \
rep(i, x.size()) { \
cout << x[i] << " "; \
cout << endl; \
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
int main() {
ll n;
cin >> n;
set<ll> st;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
st.insert(i);
st.insert(n / i);
}
}
ll ans = 0;
for (ll x : st) {
ll m = n / x - 1;
if (n / m == n % m)
ans += m;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) \
rep(i, x.size()) { \
cout << x[i] << " "; \
cout << endl; \
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
int main() {
ll n;
cin >> n;
set<ll> st;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
st.insert(i);
st.insert(n / i);
}
}
ll ans = 0;
for (ll x : st) {
ll m = n / x - 1;
if (m == 0)
continue;
if (n / m == n % m)
ans += m;
}
cout << ans << endl;
} | insert | 48 | 48 | 48 | 50 | -8 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
set<ll> a;
int main() {
ll n;
cin >> n;
ll m = sqrt(n);
for (ll i = 1; i <= m; i++) {
if (n % i != 0) {
continue;
}
ll now = n / i;
ll ma = max(now, i);
ma--;
ll mi = min(now, i);
if (n / ma == mi) {
a.insert(ma);
}
}
ll ans = 0;
for (auto itr = a.begin(); itr != a.end(); itr++) {
ans += *itr;
}
cout << ans;
// your code goes here
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
set<ll> a;
int main() {
ll n;
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
ll m = sqrt(n);
for (ll i = 1; i <= m; i++) {
if (n % i != 0) {
continue;
}
ll now = n / i;
ll ma = max(now, i);
ma--;
ll mi = min(now, i);
if (n / ma == mi) {
a.insert(ma);
}
}
ll ans = 0;
for (auto itr = a.begin(); itr != a.end(); itr++) {
ans += *itr;
}
cout << ans;
// your code goes here
return 0;
} | insert | 10 | 10 | 10 | 14 | 0 | |
p03050 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
long long N;
cin >> N;
long long ans = 0;
for (long long i = 1; i * i <= N; i++) {
if (N % i == 0) {
long long a = i, b = N / i;
if (a - 1 > 0 && N % (a - 1) == (N / (a - 1)))
ans += a - 1;
if (N % (b - 1) == N / (b - 1))
ans += b - 1;
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
long long N;
cin >> N;
long long ans = 0;
for (long long i = 1; i * i <= N; i++) {
if (N % i == 0) {
long long a = i, b = N / i;
if (a - 1 > 0 && N % (a - 1) == (N / (a - 1)))
ans += a - 1;
if (b != a && b - 1 > 0 && N % (b - 1) == N / (b - 1))
ans += b - 1;
}
}
cout << ans << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define st(arr, a) memset(arr, a, sizeof arr)
#define nl cout << endl
#define real signed
#define endl '\n'
#define bitcount(x) __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define rfor(i, a, b) for (int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define X first
#define Y second
#define N 314159
#define vi vector<int>
#define v vector
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
set<int> dc;
int sum = 0;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
dc.insert(i);
dc.insert(n / i);
}
}
dc.insert(n);
for (auto i : dc) {
int x = i * (n % (i - 1));
if (x == n)
sum += i - 1;
}
cout << sum;
return 0;
}
// g++ -g c.cpp ; ./a.exe | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define st(arr, a) memset(arr, a, sizeof arr)
#define nl cout << endl
#define real signed
#define endl '\n'
#define bitcount(x) __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define rfor(i, a, b) for (int i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define pi pair<int, int>
#define X first
#define Y second
#define N 314159
#define vi vector<int>
#define v vector
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
set<int> dc;
int sum = 0;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
dc.insert(i);
dc.insert(n / i);
}
}
if (n != 1)
dc.insert(n);
for (auto i : dc) {
int x = i * (n % (i - 1));
if (x == n)
sum += i - 1;
}
cout << sum;
return 0;
}
// g++ -g c.cpp ; ./a.exe | replace | 35 | 36 | 35 | 37 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
ll n;
cin >> n;
ll ans = 0;
for (ll a = 1; a <= n; a++) {
if (n % a == 0) {
ll m = n / a - 1;
if (m <= a)
break;
if (m >= 1)
ans += m;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
ll n;
cin >> n;
ll ans = 0;
for (ll a = 1; a * a <= n; a++) {
if (n % a == 0) {
ll m = n / a - 1;
if (m <= a)
break;
if (m >= 1)
ans += m;
}
}
cout << ans << endl;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define rep1(i, n) for (auto i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
struct init {
init() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
int main() {
ll n;
cin >> n;
ll sum = 0;
rep1(k, n) {
if (n % k == 0) {
ll m = (n / k) - 1;
if (m <= 0)
break;
if (n % m != k)
break;
sum += m;
}
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define rep1(i, n) for (auto i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
struct init {
init() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
int main() {
ll n;
cin >> n;
ll sum = 0;
ll sq = n / (ll)sqrt(n) + 5;
rep1(k, sq) {
if (n % k == 0) {
ll m = (n / k) - 1;
if (m <= 0)
break;
if (n % m != k)
break;
sum += m;
}
}
cout << sum << endl;
return 0;
}
| replace | 23 | 24 | 23 | 25 | TLE | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include"testlib.h"
using namespace std;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;
int main(int argc, char *argv[]) {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
ll n;
cin >> n;
ll sq = sqrtl(n);
while (sq * sq < n)
sq++;
while (sq * sq > n)
sq--;
// ll sum = 0;
// for(int i = 1; i <= n; ++i){
// if(n / i == n % i) sum += i;
// }
// cout << sum << endl;
ll res = 0;
for (int i = 1; i <= sq; ++i) {
ll m = n / i;
m--;
if (n / m == n % m)
res += m;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
// #include"testlib.h"
using namespace std;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;
int main(int argc, char *argv[]) {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
ll n;
cin >> n;
ll sq = sqrtl(n);
while (sq * sq < n)
sq++;
while (sq * sq > n)
sq--;
// ll sum = 0;
// for(int i = 1; i <= n; ++i){
// if(n / i == n % i) sum += i;
// }
// cout << sum << endl;
ll res = 0;
for (int i = 1; i <= sq; ++i) {
ll m = n / i;
m--;
if (m && n / m == n % m)
res += m;
}
cout << res << endl;
return 0;
}
| replace | 40 | 41 | 40 | 41 | 0 | |
p03050 | C++ | Runtime Error | #define DivertaPC2019_D
#ifdef DivertaPC2019_D
#pragma comment(linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i)
#define BUGAVOID(x) x
#define rep(...) \
BUGAVOID(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__))
#define all(c) c.begin(), c.end()
#define mp make_pair
#define write(x) cout << (x) << "\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
template <class T> using vv = vector<vector<T>>;
template <class T> vv<T> vvec(size_t n, size_t m, T v) {
return vv<T>(n, vector<T>(m, v));
}
template <class T> bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template <class T> bool chmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60;
constexpr double EPS = 1e-6;
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
};
} aaaa;
ll N;
ll ans = 0;
int main() {
cin >> N;
if (N == 2) {
write(1);
return 0;
}
ll sqrtN = sqrt(N);
if ((sqrtN + 1) * (sqrtN + 1) == N) {
sqrtN++;
} else if ((sqrtN - 1) * (sqrtN - 1) == N) {
sqrtN--;
}
ll lim = sqrtN + 1;
for (ll k = 1; k < lim; ++k) {
ll n = N - k;
if (n % k == 0) {
ll m = n / k;
if (k % m != 0) {
if (N % m == k && N / m == k) {
ans += m;
}
}
}
}
write(ans);
}
#endif | #define DivertaPC2019_D
#ifdef DivertaPC2019_D
#pragma comment(linker, "/STACK:256000000")
#include "bits/stdc++.h"
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i)
#define BUGAVOID(x) x
#define rep(...) \
BUGAVOID(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__))
#define all(c) c.begin(), c.end()
#define mp make_pair
#define write(x) cout << (x) << "\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
template <class T> using vv = vector<vector<T>>;
template <class T> vv<T> vvec(size_t n, size_t m, T v) {
return vv<T>(n, vector<T>(m, v));
}
template <class T> bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template <class T> bool chmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60;
constexpr double EPS = 1e-6;
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
};
} aaaa;
ll N;
ll ans = 0;
int main() {
cin >> N;
if (N == 1) {
write(0);
return 0;
} else if (N == 2) {
write(0);
return 0;
}
ll sqrtN = sqrt(N);
if ((sqrtN + 1) * (sqrtN + 1) == N) {
sqrtN++;
} else if ((sqrtN - 1) * (sqrtN - 1) == N) {
sqrtN--;
}
ll lim = sqrtN + 1;
for (ll k = 1; k < lim; ++k) {
ll n = N - k;
if (n % k == 0) {
ll m = n / k;
if (k % m != 0) {
if (N % m == k && N / m == k) {
ans += m;
}
}
}
}
write(ans);
}
#endif | replace | 40 | 42 | 40 | 45 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
int main() {
ll n;
cin >> n;
vector<ll> d;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
d.push_back(i);
if (i * i != n) {
d.push_back(n / i);
}
}
}
ll ans = 0;
for (int i = 0; i < d.size(); ++i) {
if (n % (d[i] - 1) == n / (d[i] - 1)) {
ans += d[i] - 1;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
int main() {
ll n;
cin >> n;
vector<ll> d;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
d.push_back(i);
if (i * i != n) {
d.push_back(n / i);
}
}
}
ll ans = 0;
for (int i = 0; i < d.size(); ++i) {
if (d[i] != 1 && n % (d[i] - 1) == n / (d[i] - 1)) {
ans += d[i] - 1;
}
}
cout << ans << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | -8 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
int main() {
ll n;
cin >> n;
vector<ll> d;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
d.push_back(i);
if (i * i != n) {
d.push_back(n / i);
}
}
}
sort(d.rbegin(), d.rend());
ll ans = 0;
for (int i = 0; i < d.size(); ++i) {
if (n % (d[i] - 1) == n / (d[i] - 1)) {
ans += d[i] - 1;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
int main() {
ll n;
cin >> n;
vector<ll> d;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
d.push_back(i);
if (i * i != n) {
d.push_back(n / i);
}
}
}
sort(d.rbegin(), d.rend());
ll ans = 0;
for (int i = 0; i < d.size(); ++i) {
if (d[i] != 1 && n % (d[i] - 1) == n / (d[i] - 1)) {
ans += d[i] - 1;
}
}
cout << ans << endl;
return 0;
}
| replace | 26 | 27 | 26 | 27 | -8 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
long long res, n, m, i;
int main() {
cin >> n;
for (i = 1; i * i <= n; i++) {
if (n % i == 0) {
m = n / i;
m--;
if (n / m == n % m)
res += m;
;
}
}
cout << res;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
long long res, n, m, i;
int main() {
cin >> n;
for (i = 1; i * i <= n; i++) {
if (n % i == 0) {
m = n / i;
m--;
if (m != 0) {
if (n / m == n % m)
res += m;
}
}
}
cout << res;
return 0;
}
| replace | 15 | 18 | 15 | 19 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, ans;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (ll mod = 1; mod * mod <= n; mod++) {
if ((n % mod) || n % (n / mod - 1) != mod)
continue;
ans += n / mod - 1;
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, ans;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (ll mod = 1; mod * mod <= n; mod++) {
if ((n % mod) || (n == 1 && mod == 1) || n % (n / mod - 1) != mod)
continue;
ans += n / mod - 1;
}
cout << ans;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
bool check(int i) { return n / i == n % i; }
signed main() {
cin >> n;
int ans = 0ll;
for (int i = 1ll; i * i <= n; i++) {
if (n % i == 0ll) {
if (check(n / i - 1ll))
ans += (n / i - 1ll);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
bool check(int i) { return n / i == n % i; }
signed main() {
cin >> n;
int ans = 0ll;
for (int i = 1ll; i * i <= n; i++) {
if (n % i == 0ll) {
int m = n / i - 1ll;
if (m != 0 && n / m == n % m)
ans += m;
}
}
cout << ans << endl;
} | replace | 12 | 14 | 12 | 15 | 0 | |
p03050 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
ll number = 1000000000000;
cin >> number;
ll result = 0;
for (ll i = 1; i * i <= number; ++i) {
if ((number - i) % i == 0) {
ll j = (number - i) / i;
if (number / j == number % j) {
result += j;
}
}
}
cout << result << endl;
return 0;
}
| #include <cstdio>
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
ll number = 1000000000000;
cin >> number;
ll result = 0;
for (ll i = 1; i * i <= number; ++i) {
if ((number - i) % i == 0) {
ll j = (number - i) / i;
if (j == 0) {
continue;
}
if (number / j == number % j) {
result += j;
}
}
}
cout << result << endl;
return 0;
} | insert | 15 | 15 | 15 | 18 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
LL N;
LL s = 1e6 + 1;
int main() {
cin >> N;
LL ans = 0;
REP(i, sqrt(N)) {
if (N % (i + 1) == 0) {
if ((i + 1) > N / (i + 1))
continue;
LL m = N / (i + 1) - 1;
if (N / m == (N % m)) {
ans += (N / (i + 1) - 1);
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
LL N;
LL s = 1e6 + 1;
int main() {
cin >> N;
LL ans = 0;
REP(i, sqrt(N)) {
if (N % (i + 1) == 0) {
if ((i + 1) > N / (i + 1))
continue;
LL m = N / (i + 1) - 1;
if (m <= 0)
continue;
if (N / m == (N % m)) {
ans += (N / (i + 1) - 1);
}
}
}
cout << ans << endl;
} | insert | 17 | 17 | 17 | 19 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sperase(v, n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
int n, ans;
signed main() {
cin >> n;
int hoge = (int)sqrt(n);
rep1(i, hoge) {
int tmp = (n - 1) / i;
if (n / tmp == n % tmp)
ans += tmp;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sperase(v, n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
int n, ans;
signed main() {
cin >> n;
int hoge = (int)sqrt(n);
rep1(i, hoge) {
int tmp = (n - 1) / i;
if (!tmp)
continue;
if (n / tmp == n % tmp)
ans += tmp;
}
cout << ans << endl;
}
| insert | 27 | 27 | 27 | 29 | 0 | |
p03050 | C++ | Runtime Error | #include <iostream>
#include <math.h>
using namespace std;
int main() {
unsigned long sum = 0;
unsigned long n;
cin >> n;
for (unsigned long i = 1; i <= (unsigned long)sqrt(n); i++) {
if (n % i != 0)
continue;
unsigned long j = n / i;
// check i-1
if ((i - 1) != 0) {
if (n / (i - 1) == n % (i - 1))
sum += (i - 1);
}
// check j-1
if (n / (j - 1) == n % (j - 1))
sum += (j - 1);
}
cout << sum << endl;
}
| #include <iostream>
#include <math.h>
using namespace std;
int main() {
unsigned long sum = 0;
unsigned long n;
cin >> n;
for (unsigned long i = 1; i <= (unsigned long)sqrt(n); i++) {
if (n % i != 0)
continue;
unsigned long j = n / i;
// check i-1
if ((i - 1) != 0) {
if (n / (i - 1) == n % (i - 1))
sum += (i - 1);
}
// check j-1
if ((j - 1) != 0) {
if (n / (j - 1) == n % (j - 1))
sum += (j - 1);
}
}
cout << sum << endl;
}
| replace | 18 | 20 | 18 | 22 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define REP(i, x) for (int i = 0; i < x; i++)
#define REPP(i, x, y) for (int i = x; i <= y; i++)
#define SI(x) scanf("%d", &x)
#define SL(x) scanf("%lld", &x)
#define MX3(x, y, z) max({x, y, z})
#define MX4(x, y, z, p) max({x, y, z, p})
#define MX5(x, y, z, p, q) max({x, y, z, p, q})
#define MN3(x, y, z) min({x, y, z})
#define MN4(x, y, z, p) min({x, y, z, p})
#define MN5(x, y, z, p, q) min({x, y, z, p, q})
#define amax(x, y) x = max(x, y)
#define amin(x, y) x = min(x, y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef tuple<int, int, int> ti;
typedef tuple<ll, ll, ll> tl;
// #####################################################################
void solve() {
ll n;
SL(n);
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll x = n / i - 1;
if (n / x == n % x)
ans += x;
}
}
printf("%lld\n", ans);
}
void init() {}
int main() {
init();
solve();
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define REP(i, x) for (int i = 0; i < x; i++)
#define REPP(i, x, y) for (int i = x; i <= y; i++)
#define SI(x) scanf("%d", &x)
#define SL(x) scanf("%lld", &x)
#define MX3(x, y, z) max({x, y, z})
#define MX4(x, y, z, p) max({x, y, z, p})
#define MX5(x, y, z, p, q) max({x, y, z, p, q})
#define MN3(x, y, z) min({x, y, z})
#define MN4(x, y, z, p) min({x, y, z, p})
#define MN5(x, y, z, p, q) min({x, y, z, p, q})
#define amax(x, y) x = max(x, y)
#define amin(x, y) x = min(x, y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef tuple<int, int, int> ti;
typedef tuple<ll, ll, ll> tl;
// #####################################################################
void solve() {
ll n;
SL(n);
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll x = n / i - 1;
if (x == 0)
continue;
if (n / x == n % x)
ans += x;
}
}
printf("%lld\n", ans);
}
void init() {}
int main() {
init();
solve();
return 0;
}
| insert | 52 | 52 | 52 | 54 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for (ll i = 0; i < n; i++)
int main() {
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= sqrt(n); i++) {
ll t = n / i - 1;
if (n / t == n % t)
ans += t;
}
cout << ans << endl;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for (ll i = 0; i < n; i++)
int main() {
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= sqrt(n); i++) {
ll t = n / i - 1;
if (t == 0)
continue;
if (n / t == n % t)
ans += t;
}
cout << ans << endl;
} | insert | 35 | 35 | 35 | 37 | 0 | |
p03050 | C++ | Runtime Error | #include "bits/stdc++.h"
// Begin Header {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) \
Type __VA_ARGS__; \
input(__VA_ARGS__)
constexpr size_t operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };
constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;
template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;
inline void input() {}
template <class Head, class... Tail>
inline void input(Head &&head, Tail &&...tail) {
cin >> head;
input(forward<Tail>(tail)...);
}
template <class T> inline istream &operator>>(istream &is, vector<T> &vec) {
for (auto &e : vec) {
is >> e;
}
return is;
}
inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail)) {
cout << " ";
}
output(forward<Tail>(tail)...);
}
template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
static constexpr const char *delim[] = {" ", ""};
for (const auto &e : vec) {
os << e << delim[&e == &vec.back()];
}
return os;
}
template <class T> inline vector<T> makeVector(const T &initValue, size_t sz) {
return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
return vector<decltype(makeVector<T>(initValue, args...))>(
sz, makeVector<T>(initValue, args...));
}
template <class Func> class FixPoint : Func {
public:
explicit constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}
template <class... Args>
constexpr decltype(auto) operator()(Args &&...args) const {
return Func::operator()(*this, std::forward<Args>(args)...);
}
};
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func &&f) noexcept {
return FixPoint<Func>{forward<Func>(f)};
}
template <class T> inline bool chmax(T &a, const T &b) noexcept {
return b > a && (a = b, true);
}
template <class T> inline bool chmin(T &a, const T &b) noexcept {
return b < a && (a = b, true);
}
template <class T> inline T diff(const T &a, const T &b) noexcept {
return a < b ? b - a : a - b;
}
// End Header }}}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
var(intmax_t, N);
intmax_t res = 0;
for (intmax_t q = 1; q * q <= N; ++q) {
if (N % q == 0) {
const auto m = N / q - 1;
if (N / m == N % m) {
res += m;
}
}
}
output(res);
return 0;
}
| #include "bits/stdc++.h"
// Begin Header {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) \
for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) \
Type __VA_ARGS__; \
input(__VA_ARGS__)
constexpr size_t operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };
constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;
template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;
inline void input() {}
template <class Head, class... Tail>
inline void input(Head &&head, Tail &&...tail) {
cin >> head;
input(forward<Tail>(tail)...);
}
template <class T> inline istream &operator>>(istream &is, vector<T> &vec) {
for (auto &e : vec) {
is >> e;
}
return is;
}
inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail)) {
cout << " ";
}
output(forward<Tail>(tail)...);
}
template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
static constexpr const char *delim[] = {" ", ""};
for (const auto &e : vec) {
os << e << delim[&e == &vec.back()];
}
return os;
}
template <class T> inline vector<T> makeVector(const T &initValue, size_t sz) {
return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
return vector<decltype(makeVector<T>(initValue, args...))>(
sz, makeVector<T>(initValue, args...));
}
template <class Func> class FixPoint : Func {
public:
explicit constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}
template <class... Args>
constexpr decltype(auto) operator()(Args &&...args) const {
return Func::operator()(*this, std::forward<Args>(args)...);
}
};
template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func &&f) noexcept {
return FixPoint<Func>{forward<Func>(f)};
}
template <class T> inline bool chmax(T &a, const T &b) noexcept {
return b > a && (a = b, true);
}
template <class T> inline bool chmin(T &a, const T &b) noexcept {
return b < a && (a = b, true);
}
template <class T> inline T diff(const T &a, const T &b) noexcept {
return a < b ? b - a : a - b;
}
// End Header }}}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
var(intmax_t, N);
if (N == 1) {
return output(0), 0;
}
intmax_t res = 0;
for (intmax_t q = 1; q * q <= N; ++q) {
if (N % q == 0) {
const auto m = N / q - 1;
if (N / m == N % m) {
res += m;
}
}
}
output(res);
return 0;
}
| insert | 108 | 108 | 108 | 112 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n, ans;
vector<ll> v;
int main() {
cin >> n;
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
v.pb(i);
if (i * i != n) {
v.pb(n / i);
}
}
}
v.pb(n);
for (int xD = 0; xD < v.size(); xD++) {
ll x = v[xD];
if (n == x * (n / (x - 1)))
ans += x - 1;
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n, ans;
vector<ll> v;
int main() {
cin >> n;
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
v.pb(i);
if (i * i != n) {
v.pb(n / i);
}
}
}
if (n != 1)
v.pb(n);
for (int xD = 0; xD < v.size(); xD++) {
ll x = v[xD];
if (n == x * (n / (x - 1)))
ans += x - 1;
}
cout << ans;
return 0;
}
| replace | 20 | 21 | 20 | 22 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using ll = long long;
#define INF 1e9
int main() {
ll N;
cin >> N;
ll ans = 0;
for (ll i = 1; i * i <= N; i++) {
if (N % i != 0)
continue;
ll x = i - 1;
if (x != 0 && N / x == N % x) {
ans += x;
}
x = N / i - 1;
if (N / x == N % x) {
ans += x;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using ll = long long;
#define INF 1e9
int main() {
ll N;
cin >> N;
ll ans = 0;
for (ll i = 1; i * i <= N; i++) {
if (N % i != 0)
continue;
ll x = i - 1;
if (x != 0 && N / x == N % x) {
ans += x;
}
x = N / i - 1;
if (x != 0 && N / x == N % x) {
ans += x;
}
}
cout << ans << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using ll = long long;
#define INF 1e9
int main() {
ll N;
cin >> N;
if (N == 0 || N == 2) {
cout << 0 << endl;
return 0;
}
ll ans = 0;
FOR(i, 1, N) {
if ((N - i) % i == 0 && (N - i) / i > i) {
ans += (N - i) / i;
} else if ((N - i) % i == 0 && (N - i) / i <= i) {
break;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
using ll = long long;
#define INF 1e9
int main() {
ll N;
cin >> N;
if (N == 0 || N == 2) {
cout << 0 << endl;
return 0;
}
ll ans = 0;
FOR(i, 1, N) {
if ((N - i) % i == 0 && (N - i) / i > i) {
ans += (N - i) / i;
} else if ((N - i) / i <= i) {
break;
}
}
cout << ans << endl;
return 0;
}
| replace | 21 | 22 | 21 | 22 | TLE | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define mi(N) \
int N; \
cin >> N;
#define ms(s) \
string s; \
cin >> s;
#define md(d) \
double d; \
cin >> d;
#define mv(v, N) \
vi v(N); \
rep(N) cin >> v[i];
#define mod 1000000007
#define is_out_of_grid(x, y) x < 0 || y < 0 || x >= h || y >= w
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;
template <typename T> void say(T s) { cout << s << "\n"; }
template <typename T> void say(vector<T> s) {
auto itr = s.begin();
cout << *(itr++);
while (itr != s.end()) {
cout << " " << *(itr++);
}
cout << "\n";
}
template <typename T> void say(vector<T> s, char r) {
auto itr = s.begin();
cout << *(itr++);
while (itr != s.end()) {
cout << r << *(itr++);
}
cout << "\n";
}
void yn(bool b) {
if (b)
say("yes");
else
say("no");
}
void Yn(bool b) {
if (b)
say("Yes");
else
say("No");
}
void YN(bool b) {
if (b)
say("YES");
else
say("NO");
}
void Yay(bool b) {
if (b)
say("Yay!");
else
say(":(");
}
template <typename T> void maxi(T &a, T b) { a = max(a, b); }
template <typename T> void mini(T &a, T b) { a = min(a, b); }
void exact_say(double x) {
cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}
template <typename T> vector<vector<T>> fill_vector(int h, int w, T val) {
vector<vector<T>> ret;
vector<T> v(w, val);
rep(h) ret.push_back(v);
return ret;
}
vi enum_div(int n) {
vi ans;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ans.push_back(i);
if (i != 1 && i * i != n) {
ans.push_back(n / i);
}
}
}
ans.push_back(n);
return ans;
}
signed main() {
int ans = 0;
int n;
cin >> n;
vi v = enum_div(n);
v.erase(v.begin());
for (int m : v) {
m--;
if (n / m == n % m)
ans += m;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define mi(N) \
int N; \
cin >> N;
#define ms(s) \
string s; \
cin >> s;
#define md(d) \
double d; \
cin >> d;
#define mv(v, N) \
vi v(N); \
rep(N) cin >> v[i];
#define mod 1000000007
#define is_out_of_grid(x, y) x < 0 || y < 0 || x >= h || y >= w
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;
template <typename T> void say(T s) { cout << s << "\n"; }
template <typename T> void say(vector<T> s) {
auto itr = s.begin();
cout << *(itr++);
while (itr != s.end()) {
cout << " " << *(itr++);
}
cout << "\n";
}
template <typename T> void say(vector<T> s, char r) {
auto itr = s.begin();
cout << *(itr++);
while (itr != s.end()) {
cout << r << *(itr++);
}
cout << "\n";
}
void yn(bool b) {
if (b)
say("yes");
else
say("no");
}
void Yn(bool b) {
if (b)
say("Yes");
else
say("No");
}
void YN(bool b) {
if (b)
say("YES");
else
say("NO");
}
void Yay(bool b) {
if (b)
say("Yay!");
else
say(":(");
}
template <typename T> void maxi(T &a, T b) { a = max(a, b); }
template <typename T> void mini(T &a, T b) { a = min(a, b); }
void exact_say(double x) {
cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}
template <typename T> vector<vector<T>> fill_vector(int h, int w, T val) {
vector<vector<T>> ret;
vector<T> v(w, val);
rep(h) ret.push_back(v);
return ret;
}
vi enum_div(int n) {
vi ans;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ans.push_back(i);
if (i != 1 && i * i != n) {
ans.push_back(n / i);
}
}
}
ans.push_back(n);
return ans;
}
signed main() {
int ans = 0;
int n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
vi v = enum_div(n);
v.erase(v.begin());
for (int m : v) {
m--;
if (n / m == n % m)
ans += m;
}
cout << ans << endl;
} | insert | 120 | 120 | 120 | 124 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
std::string ab("AB");
int count_ab(const std::string &st) {
int ret{0};
std::size_t pos = st.find(ab);
while (pos != std::string::npos) {
++ret;
pos = st.find(ab, pos + ab.length());
}
return ret;
}
int main(int argc, char **argv) {
int64_t n, ans{0};
cin >> n;
for (int64_t i = 1; i < (n + 1) / 2; ++i) {
if (n % i == 0) {
if ((n / i - 1) > i)
ans += (n / i - 1);
else
break;
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
std::string ab("AB");
int count_ab(const std::string &st) {
int ret{0};
std::size_t pos = st.find(ab);
while (pos != std::string::npos) {
++ret;
pos = st.find(ab, pos + ab.length());
}
return ret;
}
int main(int argc, char **argv) {
int64_t n, ans{0};
cin >> n;
for (int64_t i = 1; i < floor(sqrt(n)) + 1; ++i) {
if (n % i == 0) {
if ((n / i - 1) > i)
ans += (n / i - 1);
else
break;
}
}
cout << ans << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | TLE | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
int main() {
ll n;
cin >> n;
V<int> ms(1e6 + 1);
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll m = n / i - 1;
if (n / m == n % m)
ans += m;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
int main() {
ll n;
cin >> n;
V<int> ms(1e6 + 1);
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll m = n / i - 1;
if (m == 0)
continue;
if (n / m == n % m)
ans += m;
}
}
cout << ans << endl;
}
| insert | 16 | 16 | 16 | 18 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
// #define int long long
using ll = long long;
using pii = pair<int, int>;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9 + 7;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define rfor_(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))
#define endl '\n'
const int limit = 100007;
ll N;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> N;
ll sum = 0;
for (ll k = 1; k <= N / 3; ++k) {
if (N % k == 0) {
ll m = (N - k) / k;
if (m <= k)
break;
sum += m;
// cout << m << endl;
}
}
cout << sum << endl;
return 0;
}
| #include <iostream>
using namespace std;
// #define int long long
using ll = long long;
using pii = pair<int, int>;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9 + 7;
#define for_(i, a, b) for (int i = (a); i < (b); ++i)
#define rfor_(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))
#define endl '\n'
const int limit = 100007;
ll N;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> N;
ll sum = 0;
for (ll k = 1; (k * k + k) < N; ++k) {
if (N % k == 0)
sum += (N - k) / k;
}
cout << sum << endl;
return 0;
}
| replace | 45 | 53 | 45 | 48 | TLE | |
p03050 | C++ | Runtime Error | #include <iostream>
#include <math.h>
using namespace std;
int main() {
long long ans = 0, N;
cin >> N;
for (int i = 1; i <= sqrt(N) + 1; i++) {
if (N % (N / i - 1) == N / (N / i - 1))
ans += N / i - 1;
}
cout << ans;
} | #include <iostream>
#include <math.h>
using namespace std;
int main() {
long long ans = 0, N;
cin >> N;
if (N == 1) {
cout << 0;
return 0;
}
for (int i = 1; i <= sqrt(N); i++) {
if (N % (N / i - 1) == N / (N / i - 1))
ans += N / i - 1;
}
cout << ans;
} | replace | 8 | 9 | 8 | 13 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
#define trace(x) cout << #x << "=" << x << "\n";
#define llp 1000000007
#define mod 1000000007
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
typename set<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
typename map<F, S>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
int ans = 0;
void fun(int n) {
for (int i = 1; i * i <= (n); i++) {
if (n % i == 0) {
if (n % i == i) {
if (i != 1 && (n / (i - 1)) == (n % (i - 1))) {
ans += i - 1;
}
} else {
if (i != 1 && (n / (i - 1)) == (n % (i - 1))) {
ans += i - 1;
}
if ((n / i) != 0 && (n / ((n / i) - 1)) == (n % ((n / i) - 1))) {
ans += (n / i) - 1;
}
}
}
}
}
int32_t main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
fun(n);
// int sum=0;
// for(int i=1;i<=n;i++){
// if((n/i)==(n%i)){
// deb(i);
// sum+=i;
// }
// }
// cout<<sum<<"\n";
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
#define trace(x) cout << #x << "=" << x << "\n";
#define llp 1000000007
#define mod 1000000007
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
typename set<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
typename map<F, S>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
int ans = 0;
void fun(int n) {
for (int i = 1; i * i <= (n); i++) {
if (n % i == 0) {
if (n % i == i) {
if (i != 1 && (n / (i - 1)) == (n % (i - 1))) {
ans += i - 1;
}
} else {
if (i != 1 && (n / (i - 1)) == (n % (i - 1))) {
ans += i - 1;
}
if ((n / i) != 0 && (n / ((n / i) - 1)) == (n % ((n / i) - 1))) {
ans += (n / i) - 1;
}
}
}
}
}
int32_t main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
if (n == 1) {
cout << 0 << "\n";
return 0;
}
fun(n);
// int sum=0;
// for(int i=1;i<=n;i++){
// if((n/i)==(n%i)){
// deb(i);
// sum+=i;
// }
// }
// cout<<sum<<"\n";
cout << ans << "\n";
return 0;
} | insert | 81 | 81 | 81 | 86 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
ll N;
cin >> N;
ll ans = 0;
ll sq = sqrt(N);
for (ll i = 1; i <= sq; i++) {
if (N % i == 0) {
ll m = N / i - 1;
if (N / m == N % m)
ans += m;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
ll N;
cin >> N;
if (N == 1) {
cout << "0" << endl;
return 0;
}
ll ans = 0;
ll sq = sqrt(N);
for (ll i = 1; i <= sq; i++) {
if (N % i == 0) {
ll m = N / i - 1;
if (N / m == N % m)
ans += m;
}
}
cout << ans << endl;
return 0;
}
| insert | 8 | 8 | 8 | 12 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)
typedef long long ll;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
ll res = 0;
cin >> n;
for (ll i = 1; i * i <= n; ++i) {
if (n % i != 0)
continue;
ll j = n / i - 1;
ll k = i - 1;
if (k != 0 && n / k == n % k)
res += k;
if (n / j == n % j)
res += j;
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)
typedef long long ll;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
ll res = 0;
cin >> n;
for (ll i = 1; i * i <= n; ++i) {
if (n % i != 0)
continue;
ll j = n / i - 1;
ll k = i - 1;
if (k != 0 && n / k == n % k)
res += k;
if (j != 0 && n / j == n % j)
res += j;
}
cout << res << endl;
return 0;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor, dividend) (divisor + (dividend - 1)) / dividend
long long int n, ans = 0;
std::vector<long long int> v;
std::vector<long long int> enum_div(long long int n) {
std::vector<long long int> ret;
for (long long int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n)
ret.push_back(n / i);
}
}
ret.push_back(n);
sort(ret.begin(), ret.end());
return ret;
}
int main() {
cin >> n;
v = enum_div(n);
for (long long int i = 1; i < v.size(); i++) {
if (floor(n / (v[i] - 1)) == n % (v[i] - 1))
ans += (v[i] - 1);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor, dividend) (divisor + (dividend - 1)) / dividend
long long int n, ans = 0;
std::vector<long long int> v;
std::vector<long long int> enum_div(long long int n) {
std::vector<long long int> ret;
for (long long int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n)
ret.push_back(n / i);
}
}
ret.push_back(n);
sort(ret.begin(), ret.end());
return ret;
}
int main() {
cin >> n;
v = enum_div(n);
for (long long int i = 0; i < v.size(); i++) {
if (v[i] - 1 == 0)
continue;
if (floor(n / (v[i] - 1)) == n % (v[i] - 1))
ans += (v[i] - 1);
}
cout << ans << endl;
}
| replace | 23 | 24 | 23 | 26 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a, b) pb(m_p(a, b))
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) \
sort(all(a)); \
reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)), a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout << endl
#define debg(a) cout << #a << " " << a << endl;
#define call(a) \
for (auto i : a) \
cout << i << " "; \
cout << endl
#define show(a) \
rep(ghf, SZ(a)) { \
rep(kjh, SZ(a[ghf])) { \
cout << (a[ghf][kjh] < 10 ? " " : "") << a[ghf][kjh] << " "; \
} \
ENDL; \
}
#define out(a) cout << (a) << endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll, ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int max(int a, int b) {
if (a > b)
return a;
return b;
}
int min(int a, int b) {
if (a > b)
return b;
return a;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YN(bool b) { cout << (b ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
V divisor;
for (ll i = 1; i * i <= n; ++i)
if (n % i == 0)
divisor.pb(i);
// call(divisor);
ll res = 0;
for (const auto &m : divisor) {
ll k = (n - m) / m;
if (n % k == n / k)
res += k;
}
out(res);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a, b) pb(m_p(a, b))
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) \
sort(all(a)); \
reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)), a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout << endl
#define debg(a) cout << #a << " " << a << endl;
#define call(a) \
for (auto i : a) \
cout << i << " "; \
cout << endl
#define show(a) \
rep(ghf, SZ(a)) { \
rep(kjh, SZ(a[ghf])) { \
cout << (a[ghf][kjh] < 10 ? " " : "") << a[ghf][kjh] << " "; \
} \
ENDL; \
}
#define out(a) cout << (a) << endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll, ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int max(int a, int b) {
if (a > b)
return a;
return b;
}
int min(int a, int b) {
if (a > b)
return b;
return a;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YN(bool b) { cout << (b ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
V divisor;
for (ll i = 1; i * i <= n; ++i)
if (n % i == 0)
divisor.pb(i);
// call(divisor);
ll res = 0;
for (const auto &m : divisor) {
ll k = (n - m) / m;
if (n % k == n / k)
res += k;
}
out(res);
return 0;
}
| replace | 84 | 85 | 84 | 88 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
long long n;
scanf("%lld", &n);
long long ans = 0;
for (long long i = 1; i * i <= n; ++i) {
if (n % i)
continue;
if (i > 1 && n % (i - 1) == n / (i - 1))
ans += i - 1;
if (n % (n / i - 1) == n / (n / i - 1))
ans += n / i - 1;
}
printf("%lld", ans);
}
int main() {
init();
int t = 1; // scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
long long n;
scanf("%lld", &n);
long long ans = 0;
for (long long i = 1; i * i <= n; ++i) {
if (n % i)
continue;
if (i > 1 && n % (i - 1) == n / (i - 1))
ans += i - 1;
if (n / i > 1 && n % (n / i - 1) == n / (n / i - 1))
ans += n / i - 1;
}
printf("%lld", ans);
}
int main() {
init();
int t = 1; // scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
ll n;
cin >> n;
ll answer = 0;
for (ll i = 1; i * i <= n; ++i) {
const ll m = (n - i) / i;
if (n % m == n / m) {
answer += m;
}
}
cout << answer << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
ll n;
cin >> n;
ll answer = 0;
for (ll i = 1; i * i <= n; ++i) {
const ll m = (n - i) / i;
if (m != 0 && n % m == n / m) {
answer += m;
}
}
cout << answer << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve() {
ll N, ans, m2;
ans = 0;
cin >> N;
m2 = 0;
/*
for (ll m = 2; m <= N; ++m) {
if (N > m * m) continue;
if (N / m == N % m) {
m2 = N / m;
cout << N << " = " << m << " * " << m2 << " + " << m2 << endl;
//break;
}
}
if (m2 == 0) {
return 0;
}
*/
m2 = (ll)pow(N, 0.5) + 1;
for (ll m = 1; m <= m2; ++m) {
if (N % m == 0) {
ll b = N / m - 1;
if (N / b == N % b) {
ans += b;
}
}
}
return ans;
}
int main() { cout << solve() << endl; }
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve() {
ll N, ans, m2;
ans = 0;
cin >> N;
m2 = 0;
/*
for (ll m = 2; m <= N; ++m) {
if (N > m * m) continue;
if (N / m == N % m) {
m2 = N / m;
cout << N << " = " << m << " * " << m2 << " + " << m2 << endl;
//break;
}
}
if (m2 == 0) {
return 0;
}
*/
m2 = (ll)pow(N, 0.5) + 1;
for (ll m = 1; m <= m2; ++m) {
if (N % m == 0) {
ll b = N / m - 1;
if (b != 0) {
if (N / b == N % b) {
ans += b;
}
}
}
}
return ans;
}
int main() { cout << solve() << endl; }
| replace | 27 | 29 | 27 | 31 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e4 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1e9 + 7,
INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r - l) >> 1)
#define lson o << 1, l, m
#define rson o << 1 | 1, m + 1, r
#define lc(x) ch[x][0]
#define pii pair<int, int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i, a, b) for (RR i = (a); i <= (b); ++i)
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
ll n, ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
ll m;
rep(i, 2, sqrt(n)) {
if (n % i == 0) {
m = i - 1;
if (n / m == n / i)
ans += m;
ll tmp = n / i;
if (tmp == i)
continue;
m = tmp - 1;
if (n / m == n / tmp)
ans += m;
}
}
if (n / (n - 1) == 1)
ans += n - 1;
cout << ans << '\n';
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e4 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1e9 + 7,
INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r - l) >> 1)
#define lson o << 1, l, m
#define rson o << 1 | 1, m + 1, r
#define lc(x) ch[x][0]
#define pii pair<int, int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i, a, b) for (RR i = (a); i <= (b); ++i)
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
ll n, ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
ll m;
rep(i, 2, sqrt(n)) {
if (n % i == 0) {
m = i - 1;
if (n / m == n / i)
ans += m;
ll tmp = n / i;
if (tmp == i)
continue;
m = tmp - 1;
if (n / m == n / tmp)
ans += m;
}
}
if (n > 1 && n / (n - 1) == 1)
ans += n - 1;
cout << ans << '\n';
return 0;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VL;
typedef pair<ll, ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i, x, y) for (ll i = x; i < y; i++)
#define frr(i, x, y) for (ll i = x - 1; i >= y; i--)
#define inf 10000000000000000
const ll mod = 998244353;
void solve() {
ll n;
cin >> n;
ll sum = 0;
fr(i, 1, n + 1) {
if (n / i == (n % i)) {
sum += i;
}
}
cout << sum << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VL;
typedef pair<ll, ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i, x, y) for (ll i = x; i < y; i++)
#define frr(i, x, y) for (ll i = x - 1; i >= y; i--)
#define inf 10000000000000000
const ll mod = 998244353;
void solve() {
ll n;
cin >> n;
ll sum = 0;
for (ll i = 1; i * i <= n; i++) {
if ((n % i == 0)) {
ll x = n / i;
if (x - 1 > i) {
sum += (x - 1);
}
// x--;
// sum+=x;
}
}
cout << sum << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
} | replace | 19 | 22 | 19 | 27 | TLE | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main() {
ll N;
cin >> N;
auto result = 0ll;
for (auto i = 1ll; i * i <= N; ++i) {
if ((N - i) % i == 0 && (N % ((N - i) / i)) == i) {
result += (N - i) / i;
}
}
cout << result << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main() {
ll N;
cin >> N;
auto result = 0ll;
for (auto i = 1ll; i * i <= N; ++i) {
if ((N - i) > 0 && (N - i) % i == 0 && (N % ((N - i) / i)) == i) {
result += (N - i) / i;
}
}
cout << result << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
while (b) {
swap(a %= b, b);
}
return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <typename T> void fin(T mes) {
cout << mes << endl;
exit(0);
}
template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
os << "(" << rhs.first << ", " << rhs.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
struct setup {
static constexpr int PREC = 20;
setup() {
cout << fixed << setprecision(PREC);
cerr << fixed << setprecision(PREC);
};
} setup;
int N;
signed main() {
cin >> N;
int ans = 0;
for (int i = 1; i * i <= N; i++) {
if (N % i != 0) {
continue;
}
int m = (N - i) / i;
if (N / m == N % m) {
ans += m;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template <typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
while (b) {
swap(a %= b, b);
}
return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <typename T> void fin(T mes) {
cout << mes << endl;
exit(0);
}
template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
os << "(" << rhs.first << ", " << rhs.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
os << "{";
for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
os << *itr << (next(itr) != rhs.end() ? ", " : "");
}
os << "}";
return os;
}
struct setup {
static constexpr int PREC = 20;
setup() {
cout << fixed << setprecision(PREC);
cerr << fixed << setprecision(PREC);
};
} setup;
int N;
signed main() {
cin >> N;
int ans = 0;
for (int i = 1; i * i < N; i++) {
if (N % i != 0) {
continue;
}
int m = (N - i) / i;
if (N / m == N % m) {
ans += m;
}
}
cout << ans << endl;
}
| replace | 70 | 71 | 70 | 71 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
bool check(ll n, ll x) { return n % x == n / x; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll x = n / i - 1;
if (check(n, x)) {
ans += x;
}
}
}
cout << ans << endl;
/*
for (ll i = 1; i <= n; i++) {
if (n % i == n / i) {
cout << n / i << " " << i << endl;
cout << n / (i + 1) * i + n / (i + 1) << endl;
ans -= i;
}
}
dump(ans);
*/
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
bool check(ll n, ll x) { return n % x == n / x; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0 && n / i > 1) {
ll x = n / i - 1;
if (check(n, x)) {
ans += x;
}
}
}
cout << ans << endl;
/*
for (ll i = 1; i <= n; i++) {
if (n % i == n / i) {
cout << n / i << " " << i << endl;
cout << n / (i + 1) * i + n / (i + 1) << endl;
ans -= i;
}
}
dump(ans);
*/
return 0;
}
| replace | 32 | 33 | 32 | 33 | 0 | |
p03050 | C++ | Runtime Error |
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
/******************************define*********************************/
/*****************************functions********************************/
/****************************main function*****************************/
int main(void) {
ll N;
cin >> N;
ll ans = 0;
for (ll n = 1; n <= sqrt(N); n++) {
if (N % n == 0) {
if (n != 1) {
if (N / (n - 1) == N % (n - 1))
ans += n - 1;
}
if (N * n / (N - n) == N % (N / n - 1))
ans += N / n - 1;
}
}
cout << ans << endl;
return 0;
} |
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
/******************************define*********************************/
/*****************************functions********************************/
/****************************main function*****************************/
int main(void) {
ll N;
cin >> N;
ll ans = 0;
if (N == 1) {
cout << 0 << endl;
return 0;
}
for (ll n = 1; n <= sqrt(N); n++) {
if (N % n == 0) {
if (n != 1) {
if (N / (n - 1) == N % (n - 1))
ans += n - 1;
}
if (N * n / (N - n) == N % (N / n - 1))
ans += N / n - 1;
}
}
cout << ans << endl;
return 0;
} | insert | 28 | 28 | 28 | 32 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
bool check(ll n, ll x) { return n % x == n / x; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (check(n, i)) {
ans += i;
}
ll x = n / i - 1;
if (x != i && check(n, x)) {
ans += x;
}
}
}
cout << ans << endl;
/*
for (ll i = 1; i <= n; i++) {
if (n % i == n / i) {
cout << n / i << " " << i << endl;
cout << n / (i + 1) * i + n / (i + 1) << endl;
ans -= i;
}
}
dump(ans);
//*/
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif
using namespace std;
typedef long long int ll;
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
bool check(ll n, ll x) {
if (x == 0)
return false;
return n % x == n / x;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (check(n, i)) {
ans += i;
}
ll x = n / i - 1;
if (x != i && check(n, x)) {
ans += x;
}
}
}
cout << ans << endl;
/*
for (ll i = 1; i <= n; i++) {
if (n % i == n / i) {
cout << n / i << " " << i << endl;
cout << n / (i + 1) * i + n / (i + 1) << endl;
ans -= i;
}
}
dump(ans);
//*/
return 0;
}
| replace | 23 | 24 | 23 | 28 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N, sum;
cin >> N;
sum = (ll)0;
for (ll m = 1; m * m <= N; m++) {
ll t = N / m - 1;
if (N / t == N % t) {
sum += t;
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N, sum;
cin >> N;
sum = (ll)0;
if (N != 1) {
for (ll m = 1; m * m <= N; m++) {
ll t = N / m - 1;
if (N / t == N % t) {
sum += t;
}
}
}
cout << sum << endl;
return 0;
} | replace | 10 | 14 | 10 | 16 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
vector<P> prifac(ll n) {
vector<P> ret;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int cnt = 0;
while (n % i == 0) {
cnt++;
n /= i;
}
ret.push_back(P(i, cnt));
}
}
if (n > 1)
ret.push_back(P(n, 1));
return ret;
}
vector<ll> divisors(ll n) {
vector<P> vec = prifac(n);
vector<ll> ret;
ret.push_back(1);
for (int i = 0; i < vec.size(); i++) {
P p = vec[i];
int m = ret.size();
for (int j = 0; j < m; j++) {
ll t = ret[j];
for (int k = 0; k < p.second; k++) {
t *= p.first;
ret.push_back(t);
}
}
}
return ret;
}
int main() {
ll n;
cin >> n;
vector<ll> vec = divisors(n);
ll ret = 0;
for (int i = 0; i < vec.size(); i++) {
if (n / vec[i] + 2 <= vec[i])
ret += vec[i] - 1;
}
cout << ret << endl;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
vector<P> prifac(ll n) {
vector<P> ret;
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
int cnt = 0;
while (n % i == 0) {
cnt++;
n /= i;
}
ret.push_back(P(i, cnt));
}
}
if (n > 1)
ret.push_back(P(n, 1));
return ret;
}
vector<ll> divisors(ll n) {
vector<P> vec = prifac(n);
vector<ll> ret;
ret.push_back(1);
for (int i = 0; i < vec.size(); i++) {
P p = vec[i];
int m = ret.size();
for (int j = 0; j < m; j++) {
ll t = ret[j];
for (int k = 0; k < p.second; k++) {
t *= p.first;
ret.push_back(t);
}
}
}
return ret;
}
int main() {
ll n;
cin >> n;
vector<ll> vec = divisors(n);
ll ret = 0;
for (int i = 0; i < vec.size(); i++) {
if (n / vec[i] + 2 <= vec[i])
ret += vec[i] - 1;
}
cout << ret << endl;
}
| replace | 11 | 12 | 11 | 12 | TLE | |
p03050 | Python | Runtime Error | N = int(input())
lim = int(N**0.5) + 1
ans = 0
for i in range(1, lim + 1):
m = N // i
quotient = N // m
while m != 0:
remainder = N % m
if N // m != quotient or remainder > i:
break
if quotient == remainder:
ans += m
break
m -= 1
print(ans)
| N = int(input())
lim = int(N**0.5)
ans = 0
for i in range(1, lim + 1):
m = N // i
quotient = N // m
while m != 0:
remainder = N % m
if N // m != quotient or remainder > i:
break
if quotient == remainder:
ans += m
break
m -= 1
print(ans)
| replace | 1 | 2 | 1 | 2 | 0 | |
p03050 | Python | Runtime Error | import math
N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
if N % i:
continue
m = N // i - 1
if N // m == N % m:
ans += m
print(ans)
| import math
N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
if N % i:
continue
m = N // i - 1
if m <= 0:
continue
if N // m == N % m:
ans += m
print(ans)
| insert | 8 | 8 | 8 | 10 | 0 | |
p03050 | Python | Runtime Error | n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
m = n // i - 1
if n % m == n // m:
ans += m
print(ans)
| n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
m = n // i - 1
if m > 0 and n % m == n // m:
ans += m
print(ans)
| replace | 7 | 8 | 7 | 8 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#if __has_include("print.hpp")
#include "print.hpp"
#endif
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> p;
vector<ll> enumeration(ll n) {
vector<ll> result;
for (ll i = 1; i <= pow(n, 0.5) + 1; i++) {
if (n % i == 0) {
result.push_back(i);
result.push_back(n / i);
}
}
sort(ALL(result));
return result;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
vector<ll> yakusu = enumeration(n);
ll res = 0;
yakusu.erase(yakusu.begin());
for (auto a : yakusu) {
if (n % (a - 1) == n / (a - 1))
res += a - 1;
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#if __has_include("print.hpp")
#include "print.hpp"
#endif
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> p;
vector<ll> enumeration(ll n) {
vector<ll> result;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
result.push_back(i);
result.push_back(n / i);
}
}
sort(ALL(result));
return result;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
vector<ll> yakusu = enumeration(n);
ll res = 0;
yakusu.erase(yakusu.begin());
for (auto a : yakusu) {
if (n % (a - 1) == n / (a - 1))
res += a - 1;
}
cout << res << endl;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
int main() {
long long n;
std::cin >> n;
long long ans = 0;
for (long long i = 1; i <= std::sqrt(n); ++i) {
if (0 == n % i) {
long long divisor = n / i - 1;
if (n / divisor == n % divisor) {
ans += divisor;
}
}
}
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
int main() {
long long n;
std::cin >> n;
long long ans = 0;
for (long long i = 1; i <= std::sqrt(n); ++i) {
if (0 == n % i) {
long long divisor = n / i - 1;
if (0 != divisor && n / divisor == n % divisor) {
ans += divisor;
}
}
}
std::cout << ans << std::endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
typedef pair<int, int> P;
// typedef long long int ll;
int ans;
signed main() {
int n;
cin >> n;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0 && n / (n / i - 1) == n % (n / i - 1)) {
ans += n / i - 1;
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
typedef pair<int, int> P;
// typedef long long int ll;
int ans;
signed main() {
int n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i * i <= n; i++) {
if (n % i == 0 && n / (n / i - 1) == n % (n / i - 1)) {
ans += n / i - 1;
}
}
cout << ans << endl;
}
| insert | 44 | 44 | 44 | 48 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FLASH \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO \
freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); \
freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;
int n, m;
signed main() {
FLASH
cin >> n;
int ans = n - 1;
for (int i = 2; (i - 1) * (i - 1) <= n; i++) {
if (n % i != 0)
continue;
int x = n % (i - 1);
if (n == i * x)
ans += i - 1;
if (i * i == n)
continue;
x = n % (n / i - 1);
if (n == (n / i) * x)
ans += n / i - 1;
}
cout << ans;
} | #include <bits/stdc++.h>
#define FLASH \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO \
freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); \
freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
using namespace std;
int n, m;
signed main() {
FLASH
cin >> n;
int ans = n - 1;
if (n == 2)
return cout << 0, 0;
for (int i = 2; i * i <= n; i++) {
if (n % i != 0)
continue;
int x = n % (i - 1);
if (n == i * x)
ans += i - 1;
if (i * i == n)
continue;
x = n % (n / i - 1);
if (n == (n / i) * x)
ans += n / i - 1;
}
cout << ans;
} | replace | 23 | 24 | 23 | 27 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)
using namespace std;
ll n;
int main() {
// ll n;
cin >> n;
ll ans = 0;
for (int i = 1; i * i <= n; i++) {
if (n % i != 0)
continue;
if (i - 1 > n / i)
ans += i - 1;
if (n / i == i)
continue;
if (n / i - 1 > i)
ans += n / i - 1;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)
using namespace std;
ll n;
int main() {
// ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i != 0)
continue;
if (i - 1 > n / i)
ans += i - 1;
if (n / i == i)
continue;
if (n / i - 1 > i)
ans += n / i - 1;
}
cout << ans << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p03050 | Python | Runtime Error | n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
if n % i == 0 and n // (i - 1) == n % (i - 1):
ans += i - 1
m = n // i - 1
if m > 0 and n % i == 0 and n // m == n % m:
ans += m
print(ans)
| n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
if i > 1 and n % i == 0 and n // (i - 1) == n % (i - 1):
ans += i - 1
m = n // i - 1
if m > 0 and n % i == 0 and n // m == n % m:
ans += m
print(ans)
| replace | 4 | 5 | 4 | 5 | ZeroDivisionError: integer division or modulo by zero | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03050/Python/s320442263.py", line 5, in <module>
if n % i == 0 and n // (i - 1) == n % (i - 1):
ZeroDivisionError: integer division or modulo by zero
|
p03050 | Python | Runtime Error | n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
m = n // i - 1
if n % i == 0 and n // m == n % m:
ans += m
print(ans)
| n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
m = n // i - 1
if m > 0 and n % i == 0 and n // m == n % m:
ans += m
print(ans)
| replace | 5 | 6 | 5 | 6 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
set<ll> good;
int main() {
// cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll ans = 0;
for (ll a = 1; a * a <= N; a++) {
ll delta = N - a;
if (delta % a != 0)
continue;
ll m = delta / a;
if ((N / m) == (N % m))
ans += m;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
set<ll> good;
int main() {
// cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll ans = 0;
for (ll a = 1; a * a <= N; a++) {
ll delta = N - a;
if (delta % a != 0)
continue;
ll m = delta / a;
if (m == 0)
continue;
if ((N / m) == (N % m))
ans += m;
}
cout << ans << endl;
return 0;
}
| insert | 24 | 24 | 24 | 26 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
void solve(long long N, std::vector<long long> A, std::vector<long long> K) {}
int main() {
LL N;
LL ans = 0;
cin >> N;
for (LL i = 1; i <= sqrt(N); i++) {
if (N % i == 0) {
LL m = N / i;
m -= 1;
if (N / m == N % m) {
ans += m;
}
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// conversion
//------------------------------------------
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }
// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
// clear memory
#define CLR(a) memset((a), 0, sizeof(a))
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
void solve(long long N, std::vector<long long> A, std::vector<long long> K) {}
int main() {
LL N;
LL ans = 0;
cin >> N;
for (LL i = 1; i <= sqrt(N); i++) {
if (N % i == 0) {
LL m = N / i;
m = max((LL)1, m - 1);
if (N / m == N % m) {
ans += m;
}
}
}
cout << ans << endl;
}
| replace | 91 | 92 | 91 | 92 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= n; ++i) {
if (n % i)
continue;
ll tmp = n / (i + 1) + 1;
ll up = n / i;
if (up - 1 >= tmp)
ans += up - 1;
else
break;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= sqrt(n); ++i) {
if (n % i)
continue;
ll tmp = n / (i + 1) + 1;
ll up = n / i;
if (up - 1 >= tmp)
ans += up - 1;
else
break;
}
cout << ans << endl;
}
| replace | 10 | 11 | 10 | 11 | TLE | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(x) x.begin(), x.end()
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i, n) for (int i = 1; i <= n; ++i)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define error(x) cout << #x << " " << x << endl
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
const int N = 100 * 1000;
const int mod = 1e9 + 7;
int min3(int a, int b, int c) { return min(a, min(b, c)); }
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int min4(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }
int max4(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
#define int int64_t
// int a[N+2];
int32_t main() {
IOS;
int n;
cin >> n;
int ans = 0;
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
if (n / i != i) {
// different divisor
{ // for i
int j = i - 1;
// cout<<j<<" j\n";
if ((n / j) == (n % j))
ans += j;
}
{ // i=n/i
int j = n / i;
j--;
// cout<<j<<" j\n";
if ((n / j) == (n % j))
ans += j;
}
} else {
// same divisor
int j = i - 1;
// cout<<j<<" j\n";
if ((n / j) == (n % j))
ans += j;
}
}
}
if ((n / (n - 1)) == (n % (n - 1)))
ans += n - 1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(x) x.begin(), x.end()
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i, n) for (int i = 1; i <= n; ++i)
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define error(x) cout << #x << " " << x << endl
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
const int N = 100 * 1000;
const int mod = 1e9 + 7;
int min3(int a, int b, int c) { return min(a, min(b, c)); }
int max3(int a, int b, int c) { return max(a, max(b, c)); }
int min4(int a, int b, int c, int d) { return min(min(a, b), min(c, d)); }
int max4(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }
#define int int64_t
// int a[N+2];
int32_t main() {
IOS;
int n;
cin >> n;
int ans = 0;
if (n == 1) {
cout << "0\n";
return 0;
}
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
if (n / i != i) {
// different divisor
{ // for i
int j = i - 1;
// cout<<j<<" j\n";
if ((n / j) == (n % j))
ans += j;
}
{ // i=n/i
int j = n / i;
j--;
// cout<<j<<" j\n";
if ((n / j) == (n % j))
ans += j;
}
} else {
// same divisor
int j = i - 1;
// cout<<j<<" j\n";
if ((n / j) == (n % j))
ans += j;
}
}
}
if ((n / (n - 1)) == (n % (n - 1)))
ans += n - 1;
cout << ans << endl;
return 0;
}
| insert | 38 | 38 | 38 | 42 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, ans = 0;
cin >> n;
for (ll i = 1; i * i <= n; ++i)
if (n % i == 0 && n % (n / i - 1) == i)
ans += (n / i) - 1;
print(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, ans = 0;
cin >> n;
for (ll i = 1; i * i <= n; ++i)
if (n % i == 0 && n / i > 1 && n % (n / i - 1) == i)
ans += (n / i) - 1;
print(ans);
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p03050 | Python | Runtime Error | n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
m = n // i - 1
if n // m == n % m:
ans += m
print(ans)
| n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
m = n // i - 1
if m != 0 and n // m == n % m:
ans += m
print(ans)
| replace | 6 | 7 | 6 | 7 | 0 | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N) {
// cout << N << endl;
ll ans = 0;
for (ll x = 1; x < N; ++x) {
if ((N - x) % x == 0 && x < (N - x) / x) {
// cout << x << endl;
ans += (N - x) / x;
}
}
cout << ans << endl;
}
// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
long long N;
scanf("%lld", &N);
solve(N);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N) {
// cout << N << endl;
ll ans = 0;
for (ll x = 1; x * x < N - x; ++x) {
if ((N - x) % x == 0) {
// cout << x << endl;
ans += (N - x) / x;
}
}
cout << ans << endl;
}
// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
long long N;
scanf("%lld", &N);
solve(N);
return 0;
}
| replace | 7 | 9 | 7 | 9 | TLE | |
p03050 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n;
ll cnt = 0;
// vector<ll> ans;
cin >> n;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll v = n / i - 1;
if (v > i)
cnt += v;
}
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n;
ll cnt = 0;
// vector<ll> ans;
cin >> n;
for (int i = 1; i <= 1000000; i++) {
if (n % i == 0) {
ll v = n / i - 1;
if (v > i)
cnt += v;
}
}
cout << cnt << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define RREP(i, n) RFOR(i, n, 0)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL << 60;
const long long MOD = 1000000007;
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main(void) {
ll N;
cin >> N;
ll ans = 0;
FOR(i, 1, sqrt(N) + 1) {
if (N % i == 0) {
ll p = i;
ll m = N / p - 1;
if (N / p == N % p)
ans += p;
if (N / m == N % m)
ans += m;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define RREP(i, n) RFOR(i, n, 0)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL << 60;
const long long MOD = 1000000007;
#define CLR(a) memset((a), 0, sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main(void) {
ll N;
cin >> N;
ll ans = 0;
FOR(i, 1, sqrt(N) + 1) {
if (N % i == 0) {
ll p = i;
ll m = N / p - 1;
if (N / p == N % p)
ans += p;
if (m > 0 && N / m == N % m)
ans += m;
}
}
cout << ans << endl;
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p03050 | C++ | Runtime Error | /*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;
inline void solve() {
int n, sum = 0;
cin >> n;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
int k = n / i - 1;
if (n / k == n % k)
sum += k;
}
}
cout << sum << endl;
}
signed main() {
int n = 1; // cin>>n;
while (n--)
solve();
return 0;
}
| /*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;
inline void solve() {
int n, sum = 0;
cin >> n;
if (n > 2)
sum = n - 1;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int k = n / i - 1;
if (n / k == n % k)
sum += k;
}
}
cout << sum << endl;
}
signed main() {
int n = 1; // cin>>n;
while (n--)
solve();
return 0;
}
| replace | 31 | 32 | 31 | 34 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
using ll = long long;
class range {
private:
struct I {
int x;
int operator*() { return x; }
bool operator!=(I &lhs) { return x < lhs.x; }
void operator++() { ++x; }
};
I i, n;
public:
range(int n) : i({0}), n({n}) {}
range(int i, int n) : i({i}), n({n}) {}
I &begin() { return i; }
I &end() { return n; }
};
int main() {
ll N;
cin >> N;
ll res = 0;
for (ll k = 1; k <= N; ++k) {
if (k * k > N)
break;
ll mhi = N / k;
ll lo = 1, hi = mhi;
while (hi - lo > 1) {
ll mid = (lo + hi) / 2;
if (N / mid != k)
lo = mid;
else
hi = mid;
}
ll mlo = hi;
ll llo = (N - k + (mhi - 1)) / mhi;
ll lhi = (N - k) / mlo;
for (ll el = llo; el <= lhi; ++el) {
if ((N - k) % el != 0)
continue;
ll m = (N - k) / el;
// assert(N % m == k);
// assert(N / m == k);
if (N % m == k && N / m == k)
res += m;
}
}
cout << res << endl;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
using ll = long long;
class range {
private:
struct I {
int x;
int operator*() { return x; }
bool operator!=(I &lhs) { return x < lhs.x; }
void operator++() { ++x; }
};
I i, n;
public:
range(int n) : i({0}), n({n}) {}
range(int i, int n) : i({i}), n({n}) {}
I &begin() { return i; }
I &end() { return n; }
};
int main() {
ll N;
cin >> N;
if (N == 1) {
cout << 0 << endl;
return 0;
}
ll res = 0;
for (ll k = 1; k <= N; ++k) {
if (k * k > N)
break;
ll mhi = N / k;
ll lo = 1, hi = mhi;
while (hi - lo > 1) {
ll mid = (lo + hi) / 2;
if (N / mid != k)
lo = mid;
else
hi = mid;
}
ll mlo = hi;
ll llo = (N - k + (mhi - 1)) / mhi;
ll lhi = (N - k) / mlo;
for (ll el = llo; el <= lhi; ++el) {
if ((N - k) % el != 0)
continue;
ll m = (N - k) / el;
// assert(N % m == k);
// assert(N / m == k);
if (N % m == k && N / m == k)
res += m;
}
}
cout << res << endl;
}
| insert | 33 | 33 | 33 | 38 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL N;
cin >> N;
LL ret = 0;
LL a = sqrt(N);
FOR(i, 1, a + 1) {
LL tmp = (N - i) / i;
if (N / tmp == N % tmp)
ret += tmp;
// if(ret == 2499686339916LL)
// cerr << i << endl;
}
cout << ret << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())
#define ALL(a) (a).begin(), (a).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL N;
cin >> N;
LL ret = 0;
LL a = sqrt(N);
FOR(i, 1, a + 1) {
LL tmp = (N - i) / i;
if (tmp && N / tmp == N % tmp)
ret += tmp;
// if(ret == 2499686339916LL)
// cerr << i << endl;
}
cout << ret << endl;
return 0;
}
| replace | 64 | 65 | 64 | 65 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, ans = 0;
cin >> N;
for (int x = 1; x <= sqrt(N); x++) {
if (N % x == 0) {
int64_t a = (N / x) - 1;
if (N / a == N % a)
ans += a;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t N, ans = 0;
cin >> N;
for (int x = 1; x <= sqrt(N); x++) {
if (N % x == 0) {
int64_t a = (N / x) - 1;
if (a != 0 && N / a == N % a)
ans += a;
}
}
cout << ans << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
ll sum = 0;
ll i = 1;
for (; i * i < n; i++) {
if (n / i == n % i)
sum += i;
}
for (; i >= 1; i--) {
ll tmp = (n - i);
ll m = tmp / i;
if (tmp % i)
continue;
if (n / m == n % m)
sum += m;
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
ll sum = 0;
ll i = 1;
for (; i * i < n; i++) {
if (n / i == n % i)
sum += i;
}
for (; i >= 1; i--) {
ll tmp = (n - i);
if (tmp == 0)
continue;
ll m = tmp / i;
if (tmp % i)
continue;
if (n / m == n % m)
sum += m;
}
cout << sum << endl;
} | insert | 18 | 18 | 18 | 20 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
long long prv = n;
long long ans = 0;
for (long long x = 1; x * x <= n; x++) {
long long start = prv, end = n / (x + 1) + 1;
prv = min(end, start) - 1;
if (start < end)
continue;
// cout << start << " " << end << endl;
swap(start, end);
--start;
++end;
while (end - start > 1) {
long long mid = (end + start) >> 1;
if (n % mid < x)
end = mid;
else
start = mid;
}
if (n % start == x)
ans += start;
// cout << n << " " << x << " " << start << " " << n / start << " " << n
//% start << endl;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
long long prv = n;
long long ans = 0;
for (long long x = 1; x * x <= n; x++) {
long long start = prv, end = n / (x + 1) + 1;
prv = min(end, start) - 1;
if (start < end)
continue;
// cout << start << " " << end << endl;
swap(start, end);
--start;
++end;
while (end - start > 1) {
long long mid = (end + start) >> 1;
if (n % mid < x)
end = mid;
else
start = mid;
}
if (n % start == x)
ans += start;
// cout << n << " " << x << " " << start << " " << n / start << " " << n
//% start << endl;
}
cout << ans << endl;
return 0;
}
| insert | 7 | 7 | 7 | 11 | 0 | |
p03050 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for (ll i = a; i < n; i++)
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#pragma comment(linker, "/STACK:8809999999")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<ll, pll> pllp;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ll atcmod = 998244353;
const ld eps = 1e-9;
const ll settled = 400007;
vector<pll> pe;
ll globe;
ll pussy_hacker(ll m, ll i) {
ll ans = 0;
forn(j, 0, pe[i].second + 1) {
if (i + 1 < pe.size())
ans += pussy_hacker(m, i + 1);
else if (m > 1 && (m - 1) > globe / (m - 1))
ans += m - 1;
m *= pe[i].first;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
#ifndef overlord
/*freopen("capitals.in", "r", stdin);
freopen("capitals.out", "w", stdout);*/
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
globe = n;
forn(i, 2, (ll)sqrt((ld)n) + 1) {
if (n % i == 0) {
pe.push_back({i, 0});
while (n % i == 0) {
pe.back().second++;
n /= i;
}
}
if (n == 1)
break;
}
if (n > 1)
pe.push_back({n, 1});
cout << pussy_hacker(1, 0);
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for (ll i = a; i < n; i++)
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#pragma comment(linker, "/STACK:8809999999")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<ll, pll> pllp;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ll atcmod = 998244353;
const ld eps = 1e-9;
const ll settled = 400007;
vector<pll> pe;
ll globe;
ll pussy_hacker(ll m, ll i) {
ll ans = 0;
forn(j, 0, pe[i].second + 1) {
if (i + 1 < pe.size())
ans += pussy_hacker(m, i + 1);
else if (m > 1 && (m - 1) > globe / (m - 1))
ans += m - 1;
m *= pe[i].first;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
#ifndef overlord
/*freopen("capitals.in", "r", stdin);
freopen("capitals.out", "w", stdout);*/
#else
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
globe = n;
if (n == 1) {
cout << 0;
return 0;
}
forn(i, 2, (ll)sqrt((ld)n) + 1) {
if (n % i == 0) {
pe.push_back({i, 0});
while (n % i == 0) {
pe.back().second++;
n /= i;
}
}
if (n == 1)
break;
}
if (n > 1)
pe.push_back({n, 1});
cout << pussy_hacker(1, 0);
return 0;
} | insert | 66 | 66 | 66 | 71 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <float.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b)
return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll ll_gcd(ll a, ll b) {
if (a < b)
return ll_gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
struct UnionFind {
vector<ll> par;
vector<ll> siz;
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
};
long long modpow(long long a, long long n, long long mod) {
if (n < 0)
return 0;
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
vector<int> tpsort(vector<vector<int>> &G) {
int V = G.size();
vector<int> sorted_vertices;
queue<int> que;
vector<int> indegree(V);
for (int i = 0; i < V; i++) {
for (int j = 0; j < G[i].size(); j++) {
indegree[G[i][j]]++;
}
}
for (int i = 0; i < V; i++) {
if (indegree[i] == 0) {
que.push(i);
}
}
while (que.empty() == false) {
int v = que.front();
que.pop();
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
indegree[u] -= 1;
if (indegree[u] == 0)
que.push(u);
}
sorted_vertices.push_back(v);
}
return sorted_vertices;
}
struct Point {
double x;
double y;
};
struct LineSegment {
Point start;
Point end;
};
double tenkyori(const LineSegment &line, const Point &point) {
double x0 = point.x, y0 = point.y;
double x1 = line.start.x, y1 = line.start.y;
double x2 = line.end.x, y2 = line.end.y;
double a = x2 - x1;
double b = y2 - y1;
double a2 = a * a;
double b2 = b * b;
double r2 = a2 + b2;
double tt = -(a * (x1 - x0) + b * (y1 - y0));
if (tt < 0)
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
else if (tt > r2)
return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
double f1 = a * (y1 - y0) - b * (x1 - x0);
return sqrt((f1 * f1) / r2);
}
ll merge_cnt(vector<int> &a) {
int n = a.size();
if (n <= 1) {
return 0;
}
ll cnt = 0;
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
cnt += merge_cnt(b);
cnt += merge_cnt(c);
int ai = 0, bi = 0, ci = 0;
while (ai < n) {
if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
a[ai++] = b[bi++];
} else {
cnt += n / 2 - bi;
a[ai++] = c[ci++];
}
}
return cnt;
}
struct edge {
ll to, cost;
};
typedef pair<ll, ll> P;
struct graph {
ll V;
vector<vector<edge>> G;
vector<ll> d;
graph(ll n) { init(n); }
void init(ll n) {
V = n;
G.resize(V);
d.resize(V);
for (int i = 0; i < V; i++) {
d[i] = 2000000000000000000;
}
}
void add_edge(ll s, ll t, ll cost) {
edge e;
e.to = t, e.cost = cost;
G[s].push_back(e);
}
void dijkstra(ll s) {
for (int i = 0; i < V; i++) {
d[i] = 2000000000000000000;
}
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
ll v = p.second;
if (d[v] < p.first)
continue;
for (auto e : G[v]) {
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
};
int main() {
ll n;
cin >> n;
vector<ll> z;
ll ans = 0;
for (ll i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
z.push_back(n / i);
}
}
for (int i = 0; i < z.size(); i++) {
z[i]--;
if (n % z[i] == n / z[i])
ans += z[i];
}
cout << ans << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <float.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b)
return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll ll_gcd(ll a, ll b) {
if (a < b)
return ll_gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
struct UnionFind {
vector<ll> par;
vector<ll> siz;
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
};
long long modpow(long long a, long long n, long long mod) {
if (n < 0)
return 0;
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
vector<int> tpsort(vector<vector<int>> &G) {
int V = G.size();
vector<int> sorted_vertices;
queue<int> que;
vector<int> indegree(V);
for (int i = 0; i < V; i++) {
for (int j = 0; j < G[i].size(); j++) {
indegree[G[i][j]]++;
}
}
for (int i = 0; i < V; i++) {
if (indegree[i] == 0) {
que.push(i);
}
}
while (que.empty() == false) {
int v = que.front();
que.pop();
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
indegree[u] -= 1;
if (indegree[u] == 0)
que.push(u);
}
sorted_vertices.push_back(v);
}
return sorted_vertices;
}
struct Point {
double x;
double y;
};
struct LineSegment {
Point start;
Point end;
};
double tenkyori(const LineSegment &line, const Point &point) {
double x0 = point.x, y0 = point.y;
double x1 = line.start.x, y1 = line.start.y;
double x2 = line.end.x, y2 = line.end.y;
double a = x2 - x1;
double b = y2 - y1;
double a2 = a * a;
double b2 = b * b;
double r2 = a2 + b2;
double tt = -(a * (x1 - x0) + b * (y1 - y0));
if (tt < 0)
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
else if (tt > r2)
return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
double f1 = a * (y1 - y0) - b * (x1 - x0);
return sqrt((f1 * f1) / r2);
}
ll merge_cnt(vector<int> &a) {
int n = a.size();
if (n <= 1) {
return 0;
}
ll cnt = 0;
vector<int> b(a.begin(), a.begin() + n / 2);
vector<int> c(a.begin() + n / 2, a.end());
cnt += merge_cnt(b);
cnt += merge_cnt(c);
int ai = 0, bi = 0, ci = 0;
while (ai < n) {
if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
a[ai++] = b[bi++];
} else {
cnt += n / 2 - bi;
a[ai++] = c[ci++];
}
}
return cnt;
}
struct edge {
ll to, cost;
};
typedef pair<ll, ll> P;
struct graph {
ll V;
vector<vector<edge>> G;
vector<ll> d;
graph(ll n) { init(n); }
void init(ll n) {
V = n;
G.resize(V);
d.resize(V);
for (int i = 0; i < V; i++) {
d[i] = 2000000000000000000;
}
}
void add_edge(ll s, ll t, ll cost) {
edge e;
e.to = t, e.cost = cost;
G[s].push_back(e);
}
void dijkstra(ll s) {
for (int i = 0; i < V; i++) {
d[i] = 2000000000000000000;
}
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
ll v = p.second;
if (d[v] < p.first)
continue;
for (auto e : G[v]) {
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
};
int main() {
ll n;
cin >> n;
vector<ll> z;
ll ans = 0;
for (ll i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
z.push_back(n / i);
}
}
for (int i = 0; i < z.size(); i++) {
z[i]--;
if (z[i] == 0)
break;
if (n % z[i] == n / z[i])
ans += z[i];
}
cout << ans << endl;
} | insert | 251 | 251 | 251 | 253 | 0 | |
p03050 | C++ | Runtime Error |
/*
@・ω・@
*/
/*****/
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip> //cout << fixed << setprecision(桁数);
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
// #define int long long
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vec = vector<T>;
#define debug(x) (std::cerr << x)
#define debugln(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t", n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " << (x) << "\n")
#define debug_coutvec(x) \
std::cerr << #x << " : "; \
_debug_coutvec(x)
#define debug_tabcout(n, x) \
(std::cerr << strMulti("\t", n) << #x << " : " << (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " << (x) << "\n")
#define debug_tabheadcout(n, h, x) \
(std::cerr << strMulti("\t", n) << h << " : " << (x) << "\n")
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (n); i > 0; --i)
#define step(i, a, n) for (int i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstep(i, a, n) \
for (int i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define range(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rrange(i, a, b) for (int i = (b)-1, i##_len = (a); i >= i##_len; --i)
#define repll(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1ll(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrepll(i, n) for (ll i = (n)-1; i >= 0; --i)
#define rrep1ll(i, n) for (ll i = (n); i > 0; --i)
#define stepll(i, a, n) for (ll i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstepll(i, a, n) \
for (ll i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define rangell(i, a, b) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rrangell(i, a, b) for (ll i = (b)-1, i##_len = (a); i >= i##_len; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
std::string strMulti(std::string t, int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += t;
}
return out;
}
template <class T> void _debug_coutvec(vector<T> ar, string space = " ") {
rep(i, ar.size()) { debug(ar[i] << space); }
debugln("");
}
constexpr int INF = 2000000000; // 2*10^9
constexpr ll INFL = 1ll << 60ll;
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> T divup(T a, T b) {
if (a % b == 0) {
return a / b;
}
return a / b + 1;
}
template <class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
template <class T> T mod_pow(T x, T n, const T &p) {
T ret = 1;
while (n > 0) {
if (n & 1) {
(ret *= x) %= p;
}
(x *= x) %= p;
n >>= 1;
}
return ret;
}
template <class T> T math_P(T m, T n) {
T ret = 1;
for (T i = m; i > m - n; i--) {
ret *= i;
}
return ret;
}
template <class T> T math_C(T m, T n) {
T ret = math_P(m, n);
for (T i = 2; i <= n; i++) {
ret /= i;
}
return ret;
}
template <class T> T math_gcd(T a, T b) {
if (b == 0) {
return a;
} else {
return math_gcd(b, a % b);
}
}
// constexpr ll MOD = 1000000007; // 10^9+7
constexpr ll MOD = 998244353;
/*****/
void Main() {
ll N;
cin >> N;
ll ret = 0;
for (ll a = 1; a * a <= N; ++a) {
// debug_cout(a);
if (N % a == 0) {
ll k = N / a - 1;
if (N % k == N / k) {
ret += k;
}
}
}
cout << ret;
}
/*****/
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// std::cout << std::fixed << std::setprecision(10);
/**
while (true)
{
Main();
std::cerr << flush;
cout << endl;
}
/*/
Main();
std::cerr << flush;
cout << endl;
/**/
return 0;
}
|
/*
@・ω・@
*/
/*****/
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip> //cout << fixed << setprecision(桁数);
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
// #define int long long
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template <class T> using vec = vector<T>;
#define debug(x) (std::cerr << x)
#define debugln(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t", n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " << (x) << "\n")
#define debug_coutvec(x) \
std::cerr << #x << " : "; \
_debug_coutvec(x)
#define debug_tabcout(n, x) \
(std::cerr << strMulti("\t", n) << #x << " : " << (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " << (x) << "\n")
#define debug_tabheadcout(n, h, x) \
(std::cerr << strMulti("\t", n) << h << " : " << (x) << "\n")
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (n); i > 0; --i)
#define step(i, a, n) for (int i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstep(i, a, n) \
for (int i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define range(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rrange(i, a, b) for (int i = (b)-1, i##_len = (a); i >= i##_len; --i)
#define repll(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1ll(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrepll(i, n) for (ll i = (n)-1; i >= 0; --i)
#define rrep1ll(i, n) for (ll i = (n); i > 0; --i)
#define stepll(i, a, n) for (ll i = (a), i##_len = (a) + (n); i < i##_len; ++i)
#define rstepll(i, a, n) \
for (ll i = (a) + (n)-1, i##_len = (a); i >= i##_len; --i)
#define rangell(i, a, b) for (ll i = (a), i##_len = (b); i < i##_len; ++i)
#define rrangell(i, a, b) for (ll i = (b)-1, i##_len = (a); i >= i##_len; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
std::string strMulti(std::string t, int n) {
std::string out = "";
for (int i = 0; i < n; i++) {
out += t;
}
return out;
}
template <class T> void _debug_coutvec(vector<T> ar, string space = " ") {
rep(i, ar.size()) { debug(ar[i] << space); }
debugln("");
}
constexpr int INF = 2000000000; // 2*10^9
constexpr ll INFL = 1ll << 60ll;
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> T divup(T a, T b) {
if (a % b == 0) {
return a / b;
}
return a / b + 1;
}
template <class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) {
if (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
template <class T> T mod_pow(T x, T n, const T &p) {
T ret = 1;
while (n > 0) {
if (n & 1) {
(ret *= x) %= p;
}
(x *= x) %= p;
n >>= 1;
}
return ret;
}
template <class T> T math_P(T m, T n) {
T ret = 1;
for (T i = m; i > m - n; i--) {
ret *= i;
}
return ret;
}
template <class T> T math_C(T m, T n) {
T ret = math_P(m, n);
for (T i = 2; i <= n; i++) {
ret /= i;
}
return ret;
}
template <class T> T math_gcd(T a, T b) {
if (b == 0) {
return a;
} else {
return math_gcd(b, a % b);
}
}
// constexpr ll MOD = 1000000007; // 10^9+7
constexpr ll MOD = 998244353;
/*****/
void Main() {
ll N;
cin >> N;
if (N == 1) {
cout << 0;
return;
}
ll ret = 0;
for (ll a = 1; a * a <= N; ++a) {
// debug_cout(a);
if (N % a == 0) {
ll k = N / a - 1;
if (N % k == N / k) {
ret += k;
}
}
}
cout << ret;
}
/*****/
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// std::cout << std::fixed << std::setprecision(10);
/**
while (true)
{
Main();
std::cerr << flush;
cout << endl;
}
/*/
Main();
std::cerr << flush;
cout << endl;
/**/
return 0;
}
| insert | 142 | 142 | 142 | 147 | 0 | |
p03050 | C++ | Runtime Error | /*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG // FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <limits> //setprecision
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <utility> // pair, make_pair
#include <vector> // vector
// #include <cstdio> // printf
#include <bitset> // bitset
#include <cmath> //abs,,,
#include <deque> // deque
#include <map> // map
#include <math.h> //pow,,,
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
// It is so troublesome that I include bits/stdc++.h !
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int, int> P;
// NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
if (M == 0)
return 1;
long long res = mod_pow((N * N) % MOD, M / 2);
// 最下位ビット(*N)が1の時は単独でNをかける
if (M & 1)
res = (res * N) % MOD;
return res %= MOD;
}
long long nCr(long long n, long long r) {
long long A = 1, B = 1;
// Aが分子Bが1/r!
for (long long i = n - r + 1; i <= n; i++) {
A = A * i % MOD;
}
for (long long i = 1; i <= r; i++) {
B = B * i % MOD;
}
B = mod_pow(B, MOD - 2);
B %= MOD;
// Bは割るのではなく掛ける
return (A * B) % MOD;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
// long long A,B;
bool ok(long long key, long long index) {
if (index > key)
return true;
else if (index <= key)
return false;
}
long long binary_search(long long key, long long size) {
// left,right,midはいずれもindex
long long left = -1, right = size;
while (right - left > 1) {
long long mid = left + (right - left) / 2;
long long hantei = ok(key, mid);
if (hantei)
right = mid;
else
left = mid;
}
if (left == -1)
return 0;
return left;
}
int main() {
long long N;
cin >> N;
long long ans = 0;
long long M = sqrt(N);
for (int i = 1; i <= M; i++) {
if (N % i == 0) {
ans += (N / i) - 1;
if (N / ((N / i) - 1) != N % ((N / i) - 1))
ans -= (N / i) - 1;
}
}
cout << ans << endl;
}
| /*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG // FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <limits> //setprecision
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <utility> // pair, make_pair
#include <vector> // vector
// #include <cstdio> // printf
#include <bitset> // bitset
#include <cmath> //abs,,,
#include <deque> // deque
#include <map> // map
#include <math.h> //pow,,,
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
// It is so troublesome that I include bits/stdc++.h !
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int, int> P;
// NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
if (M == 0)
return 1;
long long res = mod_pow((N * N) % MOD, M / 2);
// 最下位ビット(*N)が1の時は単独でNをかける
if (M & 1)
res = (res * N) % MOD;
return res %= MOD;
}
long long nCr(long long n, long long r) {
long long A = 1, B = 1;
// Aが分子Bが1/r!
for (long long i = n - r + 1; i <= n; i++) {
A = A * i % MOD;
}
for (long long i = 1; i <= r; i++) {
B = B * i % MOD;
}
B = mod_pow(B, MOD - 2);
B %= MOD;
// Bは割るのではなく掛ける
return (A * B) % MOD;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
// long long A,B;
bool ok(long long key, long long index) {
if (index > key)
return true;
else if (index <= key)
return false;
}
long long binary_search(long long key, long long size) {
// left,right,midはいずれもindex
long long left = -1, right = size;
while (right - left > 1) {
long long mid = left + (right - left) / 2;
long long hantei = ok(key, mid);
if (hantei)
right = mid;
else
left = mid;
}
if (left == -1)
return 0;
return left;
}
int main() {
long long N;
cin >> N;
long long ans = 0;
long long M = sqrt(N);
if (N == 1) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= M; i++) {
if (N % i == 0) {
ans += (N / i) - 1;
if (N / ((N / i) - 1) != N % ((N / i) - 1))
ans -= (N / i) - 1;
}
}
cout << ans << endl;
}
| insert | 115 | 115 | 115 | 119 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0))
#define vecb2(var, n, m) vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, 0))
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define arr(var, n) \
vec var(n); \
rep(i, n) { cin >> var[i]; }
#define arrll(var, n) \
vecll var(n); \
rep(i, n) { cin >> var[i]; }
#define arrst(var, n) \
vecst var(n); \
rep(i, n) { cin >> var[i]; }
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var) accumulate(all(var), 0)
#define f_sumll(var) accumulate(all(var), 0LL)
#define chmin(v1, v2) v1 = min(v1, v2)
#define chmax(v1, v2) v1 = max(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) \
rep(i, v.size()) { cout << v[i] << (i != v.size() - 1 ? " " : "\n"); }
void prtok(bool ok) { prt(ok ? "Yes" : "No"); }
//----------------------------------------------------------------
int main(void) {
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll m = n / i - 1;
if (n / m == n % m)
ans += m;
}
}
prt(ans);
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define vec2(var, n, m) vector<vector<int>> var(n, vector<int>(m, 0))
#define vecb2(var, n, m) vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m) vector<vector<ll>> var(n, vector<ll>(m, 0))
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define arr(var, n) \
vec var(n); \
rep(i, n) { cin >> var[i]; }
#define arrll(var, n) \
vecll var(n); \
rep(i, n) { cin >> var[i]; }
#define arrst(var, n) \
vecst var(n); \
rep(i, n) { cin >> var[i]; }
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var) accumulate(all(var), 0)
#define f_sumll(var) accumulate(all(var), 0LL)
#define chmin(v1, v2) v1 = min(v1, v2)
#define chmax(v1, v2) v1 = max(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) \
rep(i, v.size()) { cout << v[i] << (i != v.size() - 1 ? " " : "\n"); }
void prtok(bool ok) { prt(ok ? "Yes" : "No"); }
//----------------------------------------------------------------
int main(void) {
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll m = n / i - 1;
if (m < 1)
continue;
if (n / m == n % m)
ans += m;
}
}
prt(ans);
}
| insert | 51 | 51 | 51 | 53 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
long long n;
cin >> n;
long long sum = 0;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i > 1)
if (n / i == n / (i - 1))
sum += i - 1;
if (i == n / (n / i - 1))
sum += (n / i) - 1;
}
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
int main() {
long long n;
cin >> n;
long long sum = 0;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (i > 1)
if (n / i == n / (i - 1))
sum += i - 1;
if ((n / i - 1) > 0)
if (i == n / (n / i - 1))
sum += (n / i) - 1;
}
}
cout << sum << endl;
return 0;
}
| replace | 17 | 19 | 17 | 20 | 0 | |
p03050 | C++ | Runtime Error | #include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i * i <= n; ++i) {
if (n % i != 0)
continue;
ll tmp = n / i - 1;
if (n / tmp == i && n % tmp == i)
ans += tmp;
}
cout << ans << endl;
} | #include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
ll ans = 0;
for (ll i = 1; i * i <= n; ++i) {
if (n % i != 0)
continue;
ll tmp = n / i - 1;
if (n / tmp == i && n % tmp == i)
ans += tmp;
}
cout << ans << endl;
} | insert | 45 | 45 | 45 | 49 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
ll res = 0;
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
ll j = 0;
j = n / i;
if (n / (i - 1) == n % (i - 1))
res += i - 1;
if (n / (j - 1) == n % (j - 1))
res += j - 1;
}
}
if (n / (n - 1) == n % (n - 1))
res += n - 1;
cout << res << endl;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
ll res = 0;
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
ll j = 0;
j = n / i;
if (n / (i - 1) == n % (i - 1))
res += i - 1;
if (n / (j - 1) == n % (j - 1))
res += j - 1;
}
}
if (n > 1)
if (n / (n - 1) == n % (n - 1))
res += n - 1;
cout << res << endl;
} | replace | 26 | 28 | 26 | 29 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int main() {
ll n, ans = 0;
cin >> n;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll t = n / i - 1;
if (n / t == n % t) {
ans += t;
}
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
int main() {
ll n, ans = 0;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ll t = n / i - 1;
if (n / t == n % t) {
ans += t;
}
}
}
cout << ans << endl;
return 0;
}
| insert | 16 | 16 | 16 | 20 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define bug(x) cout << "zdongdebug: " << x << endl;
#define bug2(x, y) cout << "zdongdebug: " << x << " " << y << endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
int main() {
#ifdef suiyuan2009
freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
ll x;
cin >> x;
ll ret = 0;
for (int i = 1; (i * (ll)i <= x); i++) {
if (x % i == 0) {
ll m = (x / i - 1);
if (x % m == x / m)
ret += x / i - 1;
// cout<<x/i-1<<endl;
}
}
cout << ret << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define bug(x) cout << "zdongdebug: " << x << endl;
#define bug2(x, y) cout << "zdongdebug: " << x << " " << y << endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
int main() {
#ifdef suiyuan2009
freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
ll x;
cin >> x;
ll ret = 0;
for (int i = 1; (i * (ll)i <= x); i++) {
if (x % i == 0) {
ll m = (x / i - 1);
if (m >= 1 && x % m == x / m)
ret += m;
// cout<<x/i-1<<endl;
}
}
cout << ret << endl;
return 0;
} | replace | 30 | 32 | 30 | 32 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 10000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using P = pair<long, long>;
/*
const int MAX = 1000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
//テーブルの前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
//そのまま計算すると負の値になるのでMODを足す
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//二分累乗法
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
*/
/*
//UnionFind木
struct UnionFind{
vector<long long int> par; //par[i] : iの親の番号
vector<long long int> rnk; //root[i] : iの木のサイズ
//コンストラクタ
UnionFind(long long int n): par(n), rnk(n){
//木の初期化
for(long long int i = 0; i < n; i++){
par[i] = i;
rnk[i] = 1;
}
}
//データxが属する木の根を再帰で取得
long long int root(long long int x){
if(par[x] == x){
return x;
}else{
return par[x] = root(par[x]);
}
}
//xとyが同じ木に属しているかを判定
bool same(long long int x, long long int y){
return root(x) == root(y);
}
//xとyの木を併合
void unite(long long int x, long long int y){
long long int rx = root(x); //xの根
long long int ry = root(y); //yの根
if(rx == ry) return; //根が同じならそのまま
//併合するときにサイズを足し合わせる
if(rnk[rx] < rnk[ry]){
par[rx] = ry;
rnk[ry] += rnk[rx];
}else{
par[ry] = rx;
rnk[rx] += rnk[ry];
}
}
//属している木のサイズを取得
long long int size(long long int x){
return rnk[root(x)];
}
};
*/
/*
//重み付きUnionFind
template<class Abel> struct UnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
UnionFind(int n = 1, Abel SUM_UNITY = 0) {
init(n, SUM_UNITY);
}
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n); rank.resize(n); diff_weight.resize(n);
for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] =
SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
}
else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y, Abel w) {
w += weight(x); w -= weight(y);
x = root(x); y = root(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y), w = -w;
if (rank[x] == rank[y]) ++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) {
return weight(y) - weight(x);
}
};
*/
/*
//ダイクストラ
typedef struct edge{
int to;
int cost;
} edge;
vector<edge> graph[2010];
long long int d[2010];
void dijkstra(int s){
priority_queue<P, vector<P>, greater<P> > que;
for(int i = 0; i < 2010; i++){
d[i] = INF;
}
d[s] = 0;
que.push(P(s, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.first;
if (d[v] < p.second) continue;
for (int i=0; i<graph[v].size(); ++i) {
edge e = graph[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(e.to, d[e.to]));
}
}
}
}
*/
/*
#素因数分解
map<long long, long long> prime_factor(long long n) {
map<long long, long long> ret;
for(long long i = 2; i * i <= n; i++) {
while(n % i == 0) {
ret[i]++;
n /= i;
}
}
if(n != 1) ret[n] = 1;
return ret;
}
*/
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
int main() {
int64_t n;
cin >> n;
vector<int64_t> v = divisor(n);
int64_t ans = 0;
for (int64_t i = 0; i < v.size(); i++) {
if (n / (v[i] - 1) == n % (v[i] - 1))
ans += v[i] - 1;
}
cout << ans << endl;
} | #include <algorithm>
#include <complex>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 10000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using P = pair<long, long>;
/*
const int MAX = 1000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
//テーブルの前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
//そのまま計算すると負の値になるのでMODを足す
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//二分累乗法
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
*/
/*
//UnionFind木
struct UnionFind{
vector<long long int> par; //par[i] : iの親の番号
vector<long long int> rnk; //root[i] : iの木のサイズ
//コンストラクタ
UnionFind(long long int n): par(n), rnk(n){
//木の初期化
for(long long int i = 0; i < n; i++){
par[i] = i;
rnk[i] = 1;
}
}
//データxが属する木の根を再帰で取得
long long int root(long long int x){
if(par[x] == x){
return x;
}else{
return par[x] = root(par[x]);
}
}
//xとyが同じ木に属しているかを判定
bool same(long long int x, long long int y){
return root(x) == root(y);
}
//xとyの木を併合
void unite(long long int x, long long int y){
long long int rx = root(x); //xの根
long long int ry = root(y); //yの根
if(rx == ry) return; //根が同じならそのまま
//併合するときにサイズを足し合わせる
if(rnk[rx] < rnk[ry]){
par[rx] = ry;
rnk[ry] += rnk[rx];
}else{
par[ry] = rx;
rnk[rx] += rnk[ry];
}
}
//属している木のサイズを取得
long long int size(long long int x){
return rnk[root(x)];
}
};
*/
/*
//重み付きUnionFind
template<class Abel> struct UnionFind {
vector<int> par;
vector<int> rank;
vector<Abel> diff_weight;
UnionFind(int n = 1, Abel SUM_UNITY = 0) {
init(n, SUM_UNITY);
}
void init(int n = 1, Abel SUM_UNITY = 0) {
par.resize(n); rank.resize(n); diff_weight.resize(n);
for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] =
SUM_UNITY;
}
int root(int x) {
if (par[x] == x) {
return x;
}
else {
int r = root(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
Abel weight(int x) {
root(x);
return diff_weight[x];
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y, Abel w) {
w += weight(x); w -= weight(y);
x = root(x); y = root(y);
if (x == y) return false;
if (rank[x] < rank[y]) swap(x, y), w = -w;
if (rank[x] == rank[y]) ++rank[x];
par[y] = x;
diff_weight[y] = w;
return true;
}
Abel diff(int x, int y) {
return weight(y) - weight(x);
}
};
*/
/*
//ダイクストラ
typedef struct edge{
int to;
int cost;
} edge;
vector<edge> graph[2010];
long long int d[2010];
void dijkstra(int s){
priority_queue<P, vector<P>, greater<P> > que;
for(int i = 0; i < 2010; i++){
d[i] = INF;
}
d[s] = 0;
que.push(P(s, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.first;
if (d[v] < p.second) continue;
for (int i=0; i<graph[v].size(); ++i) {
edge e = graph[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(e.to, d[e.to]));
}
}
}
}
*/
/*
#素因数分解
map<long long, long long> prime_factor(long long n) {
map<long long, long long> ret;
for(long long i = 2; i * i <= n; i++) {
while(n % i == 0) {
ret[i]++;
n /= i;
}
}
if(n != 1) ret[n] = 1;
return ret;
}
*/
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
int main() {
int64_t n;
cin >> n;
vector<int64_t> v = divisor(n);
int64_t ans = 0;
for (int64_t i = 0; i < v.size(); i++) {
if (v[i] == 1)
continue;
if (n / (v[i] - 1) == n % (v[i] - 1))
ans += v[i] - 1;
}
cout << ans << endl;
} | insert | 234 | 234 | 234 | 236 | -8 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define p(s) std::cout << s;
#define pl(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
#define all(v) v.begin(), v.end()
#define showVector(v) \
REP(i, v.size()) { \
p(v[i]); \
p(" ") \
} \
pl("")
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> P_dd;
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
const int MOD = 1000000007;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
void addM(long long &a, long long b) {
a += b;
if (a >= MOD)
a -= MOD;
}
void mulM(long long &a, long long b) { a = ((a % MOD) * (b % MOD)) % MOD; }
// a^b mod M
long myPow(long a, long b, int M) {
long ret = 1;
long tmp = a;
while (b > 0) {
if ((b & 1) == 1)
ret = (ret * tmp) % M;
tmp = (tmp * tmp) % M;
b = b >> 1;
}
return ret;
}
// nCk mod M
int nCk(int n, int k, int M) {
long ret = 1;
int mi = min(k, n - k);
for (int i = 1; i <= mi; i++) {
ret = (ret * myPow(i, M - 2, M)) % M;
}
for (int i = n - mi + 1; i <= n; i++) {
ret = (ret * i) % M;
}
return (int)ret;
};
vector<pair<long long, long long>> prime_factorize(long long n) {
vector<pair<long long, long long>> res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0) {
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
int main() {
ll N;
cin >> N;
ll ans = 0;
for (ll i = 1; i <= sqrt(N); i++) {
if (N % i == 0) {
if (i != 1)
if (N / (i - 1) == N % (i - 1))
ans += i - 1;
if (N / (N / i - 1) == N % (N / i - 1))
ans += N / i - 1;
}
}
pl(ans)
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define p(s) std::cout << s;
#define pl(s) std::cout << s << endl;
#define printIf(j, s1, s2) cout << (j ? s1 : s2) << endl;
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
#define all(v) v.begin(), v.end()
#define showVector(v) \
REP(i, v.size()) { \
p(v[i]); \
p(" ") \
} \
pl("")
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> P_dd;
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
const int MOD = 1000000007;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
void addM(long long &a, long long b) {
a += b;
if (a >= MOD)
a -= MOD;
}
void mulM(long long &a, long long b) { a = ((a % MOD) * (b % MOD)) % MOD; }
// a^b mod M
long myPow(long a, long b, int M) {
long ret = 1;
long tmp = a;
while (b > 0) {
if ((b & 1) == 1)
ret = (ret * tmp) % M;
tmp = (tmp * tmp) % M;
b = b >> 1;
}
return ret;
}
// nCk mod M
int nCk(int n, int k, int M) {
long ret = 1;
int mi = min(k, n - k);
for (int i = 1; i <= mi; i++) {
ret = (ret * myPow(i, M - 2, M)) % M;
}
for (int i = n - mi + 1; i <= n; i++) {
ret = (ret * i) % M;
}
return (int)ret;
};
vector<pair<long long, long long>> prime_factorize(long long n) {
vector<pair<long long, long long>> res;
for (long long p = 2; p * p <= n; ++p) {
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0) {
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
int main() {
ll N;
cin >> N;
ll ans = 0;
for (ll i = 1; i <= sqrt(N); i++) {
if (N % i == 0) {
if (i != 1)
if (N / (i - 1) == N % (i - 1))
ans += i - 1;
if (N / i != 1)
if (N / (N / i - 1) == N % (N / i - 1))
ans += N / i - 1;
}
}
pl(ans)
return 0;
} | replace | 118 | 120 | 118 | 121 | 0 | |
p03050 | C++ | Runtime Error | #include <iostream>
using namespace std;
long long ans, n;
int main() {
cin >> n;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
long long a, b;
a = n / i;
b = i;
if (n % (a - 1) == n / a)
ans += a - 1;
if (b != a && n % (b - 1) == n / b)
ans += b - 1;
}
}
if (n / (n - 1) == 1)
ans += n - 1;
cout << ans;
} | #include <iostream>
using namespace std;
long long ans, n;
int main() {
cin >> n;
if (n == 1)
return cout << 0, 0;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
long long a, b;
a = n / i;
b = i;
if (n % (a - 1) == n / a)
ans += a - 1;
if (b != a && n % (b - 1) == n / b)
ans += b - 1;
}
}
if (n / (n - 1) == 1)
ans += n - 1;
cout << ans;
} | insert | 7 | 7 | 7 | 9 | 0 | |
p03050 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define MOD (1000000007)
using namespace std;
typedef long long int Int;
Int N;
Int sum;
int main(void) {
cin >> N;
for (Int p = 1; p <= sqrt(N); p++) {
Int m = N / p - 1;
if (N / m == N % m)
sum += m;
}
cout << sum << endl;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define MOD (1000000007)
using namespace std;
typedef long long int Int;
Int N;
Int sum;
int main(void) {
cin >> N;
for (Int p = 1; p <= sqrt(N); p++) {
Int m = (N / p) - 1;
if (m <= 0)
continue;
if (N / m == N % m)
sum += m;
}
cout << sum << endl;
}
| replace | 29 | 30 | 29 | 32 | 0 | |
p03050 | C++ | Runtime Error | #include <cmath>
#include <iostream>
using namespace std;
int main() {
long long N;
long long result = 0;
cin >> N;
long long n_sqrt = (long long)floor(sqrt((double)N));
for (long long p = 1; p <= n_sqrt; p++) {
if (N % p == 0) {
long long l = N / p;
if (p == l) {
if (N % (l - 1) == p) {
result += l - 1;
}
} else if (p > l) {
break;
} else {
if (N % (l - 1) == p) {
result += l - 1;
}
}
}
}
cout << result << endl;
return (0);
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
long long N;
long long result = 0;
cin >> N;
long long n_sqrt = (long long)floor(sqrt((double)N));
for (long long p = 1; p <= n_sqrt; p++) {
if (N % p == 0) {
long long l = N / p;
if (l == 1) {
continue;
}
if (p == l) {
if (N % (l - 1) == p) {
result += l - 1;
}
} else if (p > l) {
break;
} else {
if (N % (l - 1) == p) {
result += l - 1;
}
}
}
}
cout << result << endl;
return (0);
}
| insert | 13 | 13 | 13 | 16 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
const int N = 2e5 + 5;
int p = 1e9 + 7;
int32_t main() {
IOS;
int n;
cin >> n;
int ans = 0;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
int k = n / i - 1;
if (n % k == n / k)
ans += k;
}
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
const int N = 2e5 + 5;
int p = 1e9 + 7;
int32_t main() {
IOS;
int n;
cin >> n;
int ans = 0;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
int k = n / i - 1;
if (k)
if (n % k == n / k)
ans += k;
}
}
cout << ans;
return 0;
}
| replace | 21 | 23 | 21 | 24 | 0 | |
p03050 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long n, sm;
vector<long long> d;
bool fav(long long x) { return (n % x == (n / x)); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
long long i;
for (i = 1; 1LL * i * i < n; i++) {
if (n % i == 0) {
if (i > 1)
if (fav(i - 1))
sm += (i - 1);
if (fav(1LL * n / i - 1))
sm += (1LL * n / i - 1);
}
}
if (i * i == n && fav(i - 1))
sm += (i - 1);
cout << sm;
}
| #include <bits/stdc++.h>
using namespace std;
long long n, sm;
vector<long long> d;
bool fav(long long x) { return (n % x == (n / x)); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
if (n == 1)
return cout << 0, 0;
long long i;
for (i = 1; 1LL * i * i < n; i++) {
if (n % i == 0) {
if (i > 1)
if (fav(i - 1))
sm += (i - 1);
if (fav(1LL * n / i - 1))
sm += (1LL * n / i - 1);
}
}
if (i * i == n && fav(i - 1))
sm += (i - 1);
cout << sm;
}
| insert | 14 | 14 | 14 | 16 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.