链接:
https://www.nowcoder.com/acm/contest/81/A
来源:牛客网
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
在三维空间中,平面 x = 0, y = 0, z = 0,以及平面 x + y + z = K 围成了一个三棱锥。
整天与整数打交道的小明希望知道这个三棱锥内、上整点的数目。
他觉得数量可能很多,所以答案需要对给定的 M 取模。
整天与整数打交道的小明希望知道这个三棱锥内、上整点的数目。
他觉得数量可能很多,所以答案需要对给定的 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;
}
}