Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <chrono>
- #include <random>
- #include <cassert>
- #include <type_traits>
- #include <unordered_map>
- //#pragma comment(linker, "/STACK:16777216")
- using namespace std;
- typedef long double C;
- typedef complex<C> P;
- #define X real()
- #define Y imag()
- #define have(X, Y) (X.find(Y) != X.end())
- #define int long long
- #define Size(X) (int)X.size()
- #define ui unsigned int
- #define endl '\n'
- #define mp make_pair
- #define timer fghge
- #define y1 yjyjyju
- #define all(X) (X).begin(), (X).end()
- mt19937_64 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
- int gcd(int a, int b) {
- if (b == 0)
- return a;
- else
- return gcd(b, a % b);
- }
- void extgcd(int a, int b, int &x, int &y) {
- if (b == 0) {
- x = 1;
- y = 0;
- }
- else {
- int xt, yt;
- extgcd(b, a % b, xt, yt);
- x = yt;
- int n = a / b;
- y = xt - n * yt;
- }
- }
- int ceil(double a, double b) {
- double ans = ceil(a / b);
- if ((int)a % (int)b == 0)
- ans++;
- return ans;
- }
- int floor(double a, double b) {
- double ans = floor(a / b);
- if ((int)a % (int)b == 0)
- ans--;
- return ans;
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0), cout.tie(0);
- freopen("input.txt", "r", stdin);
- int n, x; cin >> n >> x;
- int ans = 0;
- for (int i = 2; i <= 3000; i++) {
- for (int j = 1; j < i; j++) {
- int a = i, b = -j, c = n;
- int g = gcd(a, b);
- if (c % g == 0) {
- int x, y;
- extgcd(a, b, x, y);
- x *= c / g; y *= c / g;
- int fir = b / g, sec = -a / g;
- int k;
- if (fir - sec > 0)
- k = ceil(y - x, fir - sec);
- else
- k = floor(y - x, fir - sec);
- x += k * fir;
- y += k * sec;
- if (x <= y) {
- cout << "fail";
- }
- if (y > 0) {
- ans++;
- int d = y / sec;
- if (y % sec == 0)
- d--;
- ans += d;
- }
- }
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement