1731B - Kill Demodogs - CodeForces Solution


greedy math *1100

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    
    print((n * (n + 1) * (2 * n + 1) // 3 - n * (n + 1) // 2) * 2022% 1000000007 )

C++ Code:

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
int MOD = 1e9 + 7;
#define MAX 200005

// find_by_order()
// order_of_key()
// store duplicates set int to pair<int, int>
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    PBDS;

bool cmp(pair<int, int> a, pair<int, int> b){
    return a.first < b.first;
}


signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t;
    cin >> t;

    while(t--){

        int n;
        cin >> n;

        int ans=((((n * (n+1)) % MOD) * ((4*n)-1)) % MOD * 337) % MOD;
        cout << ans << endl;
    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set
1567B - MEXor Mixup
669A - Little Artem and Presents
691B - s-palindrome
851A - Arpa and a research in Mexican wave
811A - Vladik and Courtesy
1006B - Polycarp's Practice
1422A - Fence
21D - Traveling Graph
1559B - Mocha and Red and Blue
1579C - Ticks
268B - Buttons
898A - Rounding
1372B - Omkar and Last Class of Math