直角三棱锥_抽象

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

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

在三维空间中,平面 x = 0, y = 0, z = 0,以及平面 x + y + z = K 围成了一个三棱锥。
整天与整数打交道的小明希望知道这个三棱锥内、上整点的数目。
他觉得数量可能很多,所以答案需要对给定的 M 取模。

输入描述:

输入有 1 ≤ T ≤ 105 组数据。
每组数据中,输入两个整数 0 ≤ K ≤ 109 + 7, 1 ≤ M ≤ 109 + 7,意义如题目描述。

输出描述:

对于每组数据,输出一个整数,为三棱锥内、上整点的数目对 M 取模。
示例1

输入

4
0 60
1 60
29 60
29 100007

输出

1
4
40
4960

a+b+c<=k

a+b+c+d==k

0000插板

#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int N=1e6+10;

int a[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
     //freopen("in.txt","r",stdin);
    int t;
    cin>>t;
    while(t--){
        ll n,m;
        /*
        cin>>n>>m;
        ll ans=0;
        ll t=1;
        for(int i=n+1;i>0;i--){
            ans=(ans+t*i)%m;
            t++;
        }
        */
        cin>>n>>m;
        ll a=n+1;
        ll b=n+2;
        ll c=n+3;
        if(a%2==0)a/=2;
        else if(b%2==0)b/=2;
        else if(c%2==0)c/=2;

        if(a%3==0)a/=3;
        else if(b%3==0)b/=3;
        else if(c%3==0)c/=3;

        cout<<(a*b%m)*c%m<<endl;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值