25 lines
631 B
TypeScript
25 lines
631 B
TypeScript
export {};
|
|
const input = require("fs").readFileSync(0).toString().trim().split('\n');
|
|
const MOD = BigInt(1000000007);
|
|
|
|
const power = (num: bigint, n: bigint): bigint => {
|
|
if(n===BigInt(0)) return BigInt(1);
|
|
else if(n===BigInt(1)) return num%MOD;
|
|
|
|
const half = power(num, n/BigInt(2));
|
|
let result = (half * half) % MOD;
|
|
|
|
if(n%BigInt(2) === BigInt(1)) result = (result*num)%MOD;
|
|
|
|
return result;
|
|
}
|
|
|
|
let result = BigInt(0);
|
|
|
|
for(let line of input.slice(1)) {
|
|
const [N, S] = line.split(" ").map(BigInt);
|
|
|
|
result = (result + (S * power(N, MOD - BigInt(2))) % MOD) % MOD;
|
|
}
|
|
|
|
console.log(result.toString()); |