Source Code
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define mem(a,n) memset((a),n,sizeof (a))
void fast();
ll gcd(ll x, ll y) { return(!y ? x : gcd(y, x % y)); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int dx[]{ 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[]{ 0, 0, 1, -1, 1, -1, 1, -1 };
using namespace std;
ll fpow(ll x, ll n, int mod) {
    if (n == 0)return 1 % mod;
    if (n == 1)return x % mod;
    ll ans = fpow(x, n / 2, mod);
    ans = ans * ans % mod;
    if (n & 1)ans = ans * (x % mod) % mod;
    return ans;
}
int mod = 1e9 + 7;
int main()
{
    //freopen("input.txt" ,"r" ,stdin);
   //freopen("output.txt" ,"w" ,stdout);
    fast();
    int n; cin >> n;
    vector<int>v1(n), v2(n), v3(n);
    bool test = 1;
    for (int i = 0; i < n; i++)cin >> v1[i];
    for (int i = 0; i < n; i++)cin >> v2[i];
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        if (v2[i] < v1[i]) { test = 0; break; }
        v3[i] = (v2[i] - v1[i]) / (i + 1);
        sum += v3[i];
    }
    if (!test) { cout << 0; return 0;}
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        for (ll j = 2; j <= v3[i]; j++) {
            ans *= (j % mod);
            ans %= mod;
        }
    }
    ans = fpow(ans, mod - 2, mod);
    for (ll i = 2; i <= sum; i++) {
        ans *= (i % mod);
        ans %= mod;
    }
    cout << ans;



    
    return 0;
}
void fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
Copy
N-dimensions Nourhan Hanna
GNU G++17
81 ms
2.7 MB
Wrong Answer