ACM 训练日志记录 · 思考 · 成长 提交 / 修改记录
王梓豪 / 题目列表训练档案
导出

2260B Monocarp and Projects

来源:Codeforces ★ 1100

本题活力0.23按难度、完成结果与训练证据估算

算法如山行则将至

题目描述

计算k个月内Monocarp自完成的项目总数,每轮员工和项目数递增。

代码

#include<bits/stdc++.h>
using namespace std;
__int128 stoint128(string ks)
{
    __int128 ans=0;
    for(int i=0;i<(int)ks.size();i++)
    {
        ans*=10;
        ans+=ks[i]-'0';
    }
    return ans;
}
string to_string(__int128 ans)
{
    if(ans==0) return "0";
    string s;
    if (ans<0){
        s+='-';
        ans=-ans;
        s+=to_string(ans);
    }
    else 
    {   
        while(ans>0)
        {
            s+=(char)(ans%10+'0');
            ans/=10;
        }
        reverse(s.begin(),s.end());
    }
    return s;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y;
        string ks;
        __int128 k;
        cin>>x>>y>>ks;
        k=stoint128(ks);
        __int128 ans=0;
        if(x<y)
        {__int128 cnt=0;
            for(int i=0;i<k;i++)
            {
                if(y/x==1)break;
                ans+=(y%x);
                x++;
                y++;
                cnt++;
            }
            k-=cnt;
            ans+=k*(y%x);
        }
        else if(x>y)
        {
            ans+=k*(y%x);
        }
        else if(x==y)
        {
            ans=0;
        }
        cout<<to_string(ans)<<endl;
    }
}