Wannafly交流赛1 A 有理数

本文介绍了一个简单的C++程序,用于计算有理数的特定运算:floor(p/q) - (p/q - 1),并展示了如何处理除数为零的情况。该程序包括了输入输出优化以及文件读写的配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有理数

就是求一个floor(p/q)        p/q-1

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double    dl ;
#define INF 0x7f

const int  inf = 987654321;
const int sz = 1e6 + 5;
const int mod = 1e9 + 7;
const int sqrtn = 300;

#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<int,int>
#define lowbit(x) x&(-x)
#define X first
#define Y second 

void work()
{
    int T;
    int a,b;

    cin>>T;
    while(T--)
    {
        cin>>a>>b;
        if(b==0)
        {
            cout<<"No Solution"<<endl;
            continue;
        }
        int c = a/b;
          cout<<c-(a*b<0||a%b==0)<<endl; 
         
    }
}

int main()
{
    FAST_IO ;
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    work();
    cout<<"hello"<<endl;

    return 0; 
}

 

转载于:https://www.cnblogs.com/corx/p/8504680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值