bullshit arithmetic

topic link

Title:

Multiple queries: each query contains a positive integer nn and you are asked to output the following results
∏ i = 1 n ∑ j = 1 i ∑ k = 1 ji × j × k \prod_{i=1}^n \sum_{j= 1}^i \sum_{k=1}^ji\times j\times ki=1nj=1ik=1ji×j×k
In order to avoid the result being too large, only need to output this formula pair199999 ( = 2 × 3 2 × 41 × 271 + 1 199999 (=2\times 3^2 \times 41 \times 271+1199999=2×32×41×271+1 , a prime number) modulo the result.

analyze:

First we look at this formula =
∏ i = 1 ni ∑ j = 1 ij ∑ k = 1 jk \prod_{i=1}^ni \sum_{j=1}^ij\sum_{k=1}^jki=1nij=1ijk=1jk
= ∏ i = 1 n i ∑ j = 1 i j × j ∗ ( j + 1 ) 2 =\prod_{i=1}^ni \sum_{j=1}^i j\times\frac{j*(j+1)}{2} =i=1nij=1ij×2j(j+1)
Looking at the previous continuous multiplication, if n is greater than 199999, then this formula must be divisible by 199999, so when n is greater than 199999, the answer is 0, and if it is less than 199999, we can directly maintain f ( i ) = ∑ j = 1 ij × j ∗ ( j + 1 ) 2 f(i)=\sum_{j=1}^ij\times\frac{j*(j+1)}{2}f(i)=j=1ij×2j(j+1)It is maintained with an array of prefixes. Then maintain ∏ i = 1 ni ∗ f ( i ) \prod_{i=1}^ni*f(i)i=1niAfter f ( i )
is preprocessed, it is used directly.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef unsigned long long ull;

#define x first
#define y second
#define sf scanf
#define pf printf
#define PI acos(-1)
#define inf 0x3f3f3f3f
#define lowbit(x) ((-x)&x)
#define mem(a,x) memset(a,x,sizeof(a))
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<=(b);++i)
#define repr(i,b,a) for(int i=int(b);i>=(a);--i)
#define debug(x) cout << #x << ": " << x << endl;

const int MOD = 998244353;
const int mod = 199999;
const int maxn = 2e5 + 10;
const int dx[] = {
    
    0, 1, -1, 0, 0};
const int dy[] = {
    
    0, 0, 0, 1, -1};
const int dz[] = {
    
    1, -1, 0, 0, 0, 0 };
int day[] = {
    
    0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll n,m,k,cnt;
ll f[maxn],f1[maxn];

void init(){
    
    
	for(int i=1;i<maxn;i++){
    
    
		f[i]=(f[i-1]+1ll*i*i%mod*(i+1)%mod*((mod+1)/2)%mod)%mod;
	}
	f1[0]=1;
	for(int i=1;i<maxn;i++) f1[i]=1ll*f1[i-1]*f[i]%mod*i%mod;
}
string str;
void solve()
{
    
    
	cin>>str;
	ll ans=0;
	for(int i=0;i<str.size();i++){
    
    
		ans=ans*10+str[i]-'0';
		if(ans>=mod) {
    
    
			puts("0");
			return ;
		}
	}
	printf("%lld\n",f1[ans] );
}

int main()
{
    
    
	init();
    ll t = 1;
    scanf("%lld", &t);
    while(t--)
    {
    
    
        solve();
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326263373&siteId=291194637
Recommended