跳到正文

剪贴板

剪贴板 flkab5ew

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<limits.h>
#include<list>
#include<typeinfo>
using namespace std;
template < typename T > void IntRead(T &a) { a = 0; unsigned long long A = 0; bool sign = 0; char ch = getchar(); while(!(ch >= 48 && ch <= 57) && ch != EOF) { if(ch == '-') sign = 1; ch = getchar(); } while(ch >= 48 && ch <= 57) { A = (A << 1) + (A << 3) + (ch - 48); ch = getchar(); } a = A; if(sign) a = -a; }
template < typename T > void IntWrite(T a) { char st[40]; int top = 0; if(a < 0) { putchar('-'); a *= -1; } unsigned long long A = a; do { st[++top] = (A % 10 + 48); A /= 10; } while(A != 0); while(top != 0) putchar(st[top--]); }
template < typename T > void read(T &a) { if(typeid(a) == typeid(char)) cin >> a; else if(typeid(a) == typeid(unsigned char)) cin >> a; else if(typeid(a) == typeid(short)) scanf("%hd" , &a); else if(typeid(a) == typeid(unsigned short)) scanf("%hu" , &a); else if(typeid(a) == typeid(int)) scanf("%d" , &a); else if(typeid(a) == typeid(unsigned int)) scanf("%u" , &a); else if(typeid(a) == typeid(long)) scanf("%ld" , &a); else if(typeid(a) == typeid(unsigned long)) scanf("%lu" , &a); else if(typeid(a) == typeid(long long)) scanf("%lld" , &a); else if(typeid(a) == typeid(unsigned long long)) scanf("%llu" , &a); else if(typeid(a) == typeid(float)) scanf("%f" , &a); else if(typeid(a) == typeid(double)) scanf("%lf" , &a); else if(typeid(a) == typeid(long double)) scanf("%Lf" , &a); else cin >> a; }
template < typename T > void readarray(T a[] , int start , int len) { for(int i = start ; i < start + len ; read(a[i]) , i++); }
template < typename T , typename ... L > void read(T &a , L && ... b) { read(a); read(b ...); }
template < typename T > void print(T a) { if(typeid(a) == typeid(char)) cout << a; else if(typeid(a) == typeid(unsigned char)) cout << a; else if(typeid(a) == typeid(short)) printf("%hd" , a); else if(typeid(a) == typeid(unsigned short)) printf("%hu" , a); else if(typeid(a) == typeid(int)) printf("%d" , a); else if(typeid(a) == typeid(unsigned int)) printf("%u" , a); else if(typeid(a) == typeid(long)) printf("%ld" , a); else if(typeid(a) == typeid(unsigned long)) printf("%lu" , a); else if(typeid(a) == typeid(long long)) printf("%lld" , a); else if(typeid(a) == typeid(unsigned long long)) printf("%llu" , a); else if(typeid(a) == typeid(float)) printf("%f" , a); else if(typeid(a) == typeid(double)) printf("%lf" , a); else if(typeid(a) == typeid(long double)) printf("%Lf" , a); else cout << a; }
template < typename T , typename ... L > void print(T a , L ... b) { print(a); print(b ...); }
template < typename T , typename L > void printarray(T a[] , int start , int len , L x) { for(int i = start ; i < start + len ; print(a[i] , x) , i++); }
template < typename T > void printsp(T a) { print(a); print(' ');}
template < typename T , typename ... L > void printsp(T a , L ... b) { printsp(a); printsp(b ...); }
template < typename T > void printnl(T a) { print(a); print('\n');}
template < typename T , typename ... L > void printnl(T a , L ... b) { printnl(a); printnl(b ...); }
long long ksm(long long a , long long b , long long p , long long ans = 1) { while(b) { if(b & 1) (ans *= a) %= p; (a *= a) %= p; b >>= 1; } return ans; }
const long long BASE = 10;
struct node
{
    long long a[505];
    long long len;
    node()
    {
        memset(a , 0 , sizeof(a));
        len = 1;
    }
    void res()
    {
        for(int i = 500 ; i >= 1 ; i--)
        {
            if(a[i])
            {
                len = i;
                return ;
            }
        }
        len = 1;
    }
    void up()
    {
        res();
        for(int i = 1 ; i <= len ; i++)
        {
            a[i + 1] += a[i] / BASE;
            a[i] %= BASE;
            if(a[i] < 0)
            {
                a[i] += BASE;
                a[i + 1]--;
            }
        }
        res();
    }
    void print()
    {
        res();
        if(len == 1 && a[1] == 0)
        {
            cout << 0;
            return ;
        }
        cout << a[len];
        for(int i = len - 1 ; i >= 1 ; i--)
        {
            printf("%lld" , a[i]);
        }
    }
};
bool operator < (const node &a , const node &b)
{
    if(a.len != b.len)
    {
        return a.len < b.len;
    }
    for(int i = a.len ; i >= 1 ; i--)
    {
        if(a.a[i] != b.a[i])
        {
            return a.a[i] < b.a[i];
        }
    }
}
bool operator > (const node &a , const node &b)
{
    return b < a;
}
bool operator == (const node &a , const node &b)
{
    if(a.len != b.len)
    {
        return 0;
    }
    for(int i = a.len ; i >= 1 ; i--)
    {
        if(a.a[i] != b.a[i])
        {
            return 0;
        }
    }
    return 1;
}
bool operator >= (const node &a , const node &b)
{
    return (a > b) || (a == b);
}
bool operator <= (const node &a , const node &b)
{
    return (a < b) || (a == b);
}
node operator + (const node &a , long long b)
{
    node c = a;
    c.a[1] += b;
    c.up();
    return c;
}
node operator - (const node &a , long long b)
{
    node c = a;
    c.a[1] -= b;
    c.up();
    return c;
}
node operator + (const node &a , const node &b)
{
    node c;
    for(int i = 1 ; i <= max(a.len , b.len) ; i++)
    {
        c.a[i] = a.a[i] + b.a[i];
    }
    c.up();
    return c;
}
node operator - (const node &a , const node &b)
{
    node c;
    for(int i = 1 ; i <= max(a.len , b.len) ; i++)
    {
        c.a[i] = a.a[i] - b.a[i];
    }
    c.up();
    return c;
}
node operator * (const node &a , long long b)
{
    node c = a;
    for(int i = 1 ; i <= a.len ; i++)
    {
        c.a[i] *= b;
    }
    c.up();
    return c;
}
node operator / (const node &a , long long b)
{
    node c;
	int mod = 0;
	for(int i = a.len ; i >= 1 ; i--)
	{
		mod *= BASE;
		mod += a.a[i];
		c.a[i] = mod / b;
		mod %= b;
	}
    c.up();
    return c;
}
node operator * (const node &a , const node &b)
{
    node c;
    for(int i = 1 ; i <= a.len ; i++)
    {
        for(int j = 1 ; j <= b.len ; j++)
        {
            c.a[i + j - 1] += a.a[i] * b.a[j];
            c.a[i + j] += c.a[i + j - 1] / BASE;
            c.a[i + j - 1] %= BASE;
        }
    }
    c.up();
    return c;
}
long long a , b;
node p , q , ans1 , ans2;
node day(node i)
{
    return q * i * i * i * i * i;
}
node S(node i)
{
    return (q * i * i * (i + 1) * (i + 1) * (i * i * 2 + i * 2 - 1)) / 12;
}
node calcmin()
{
    node now = p;
    node maxx = p;
    node gain;
    node i;
    i = i + 1;
    for( ; ; i = i + 1)
    {
        gain = gain + day(i);
        now = now + p;
        if(gain >= now)
        {
            break;
        }
        maxx = max(maxx , now - gain);
    }
    return maxx;
}
bool check(node mid)
{
    node cost = mid * p;
    node gain = S(mid);
    node e99;
    e99.a[100] = 1;
    e99.res();
    return gain + ans1 >= e99 + cost;
}
signed main()
{
    read(a , b);
    int cnt = 0;
    while(a)
    {
        p.a[++cnt] = a % BASE;
        a /= BASE;
    }
    p.res();
    cnt = 0;
    while(b)
    {
        q.a[++cnt] = b % BASE;
        b /= BASE;
    }
    q.res();
    ans1 = calcmin();
    ans1.print();
    print('\n');
    node l;
    node r;
    r.a[30] = 1;
    r.res();
    while(l <= r)
    {
        node mid = (l + r) / 2;
        if(check(mid))
        {
            r = mid - 1;
            ans2 = mid;
        }
        else
        {
            l = mid + 1;
        }
    }
    ans2.print();
    print('\n');
	return 0;
}