Problem G. Can LYJ Pass The CET-4?
爆long long
int128在Linux上可以编译并且能用。
cin和cout是无法输出__int128的
typedef long long ll;
inline ll pp(ll a, ll b, ll m)
{
ll c = a*b-(ll)((long double)a*b/m+0.5)*m;
return c<0 ? c+m : c; //就是算的a*b%m;
}
题目
Input
There are several test cases.
The first line contains one integer T (1 ≤ 𝑇 ≤ 105
),
indicating the number of the test cases.
Each test case contains three integer a, b, c. (1 ≤ 𝑏 ≤
𝑎 ≤ 1018 1 ≤ 𝑐 ≤ 1018 ), indicating the number of words
he can recite per day and the number of words he
forgets per day and the day left before the CET-4.
There are 3,500 words LYJ needs to recite.
Output
For each test case if LYJ can recite all the words before
the CET-4 just print the minimum day needed to do it or
just print impossible to tell LYJ it’s impossible to do
that.
Sample Input
3
2 1 3500
1 1 3500
2 1 3499
Sample Output
3500
impossible
impossible
AC代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline ll pp(ll a, ll b, ll m)
{
ll c = a*b-(ll)((long double)a*b/m+0.5)*m;
return c<0 ? c+m : c;
}
int main()
{
long long t,a,b,c;
cin>>t;
while(t--)
{
scanf("%lld%lld%lld",&a,&b,&c);
if(pp(a-b,c,1e18)<3500)cout<<"impossible"<<endl;
else
{
int x=3500.0/(a-b);
if(3500%(a-b)==0)cout<<x<<endl;
else cout<<x+1<<endl;
}
}