D. “逆“天求和

                                                        D. "逆"天求和

Problem - D - Codeforces

思路:首先对于一个数b,和质数模数mod,b的逆元存在的条件是 b%mod!=0,并且b在质数模数mod情况下的逆元为b^(mod-2),而题中需要求1~p-1的所有数对于质数模数p的逆元的和,我们能够发现1~p-1对于p的逆元正好是一个p-1的排列,即不重复的前p-1个数,这可以用n*(n-1)/2算出,假如说存在重复的,那么会有a的逆元是c,b的逆元是c,因为逆元是相互的,所以c存在了两个逆元,但是题中胡老板说只有一个逆元,所以矛盾了

// Problem: D. "逆"天求和
// Contest: Codeforces - 2023 Xiangtan Unversity Freshman Conteset
// URL: https://codeforces.com/gym/104303/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms

#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector> 
#include<set>
#include<unordered_map>
#include<ctime>
#include<cstdlib>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int> > PIII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}

int T,hackT;
int n,m,k;

void solve() {
	n=read();
	
	printf("%lld\n",(ll)n*(n-1)/2);
}   

int main() {
    // init();
    // stin();

    scanf("%d",&T);
    // T=1; 
    while(T--) hackT++,solve();
    
    return 0;       
}          

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值