分数取模(逆元)

本文详细解析了牛客网一场竞赛中的A题,题目要求计算特定的贝塔指数。通过定义long long类型和使用标准命名空间,代码实现了快速幂运算、求逆元和自定义比较函数等功能。输入为交通网络规划图的数量及其结点和边的数量,输出为贝塔指数的值。
部署运行你感兴趣的模型镜像

链接:https://ac.nowcoder.com/acm/contest/946/A
来源:牛客网

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long mod=1e9+7;

long long qpow(long long a, long long b) {
    if (b < 0) return 0;
    long long ans = 1;
    a %= mod;
    while(b) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ans;
}

long long inv(long long n) {
    return qpow(n, mod - 2);
}

bool cmp(pair<double,int> a,pair<double,int> b){
	if(a.first>b.first)return true;
	return false;
}

int main(){
	int n;
	scanf("%d",&n);
	
	vector<int> v,e;
	vector<pair<double,int> > vec;
	for(int i=1;i<=n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		v.push_back(a);
		e.push_back(b);
		vec.push_back(pair<double,int>((double)b/(double)a,i-1));
	}
	
	sort(vec.begin(),vec.end(),cmp);
	
	for(int i=1;i<=n;i++){
		int t=vec[i-1].second;
		
		cout<<(e[t]*inv(v[t])%mod)%mod<<endl;
	}
	return 0;
}

输入描述:

第一行一个整数nn,表示交通网络规划图的数量。

接下来nn行,每行两个整数ViVi和EiEi,分别表示图GiGi中的结点数量和边的数量。

输出描述:

输出共nn行,每行一个数,表示贝塔指数第ii大的交通网络的贝塔指数在模109+7109+7意义下的值。

 

您可能感兴趣的与本文相关的镜像

Seed-Coder-8B-Base

Seed-Coder-8B-Base

文本生成
Seed-Coder

Seed-Coder是一个功能强大、透明、参数高效的 8B 级开源代码模型系列,包括基础变体、指导变体和推理变体,由字节团队开源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值