1734E - Rectangular Congruence - CodeForces Solution


constructive algorithms math number theory

Please click on ads to support us..

Python Code:

n = int(input())
b = list(map(int, input().split()))
a = [[(i*j)%n for i in range(1,n+1)] for j in range(1,n+1)]
for i in range(n):
    if(b[i]!=a[i][i]):
        x = b[i]-a[i][i]
        for j in range(n):
            a[i][j] = (a[i][j]+x)%n
    print(*a[i])

C++ Code:

#include <bits/stdc++.h>
#include <unordered_map>
#include <chrono>
#define endl '\n'
using namespace std;
const int N = 1e6 + 10, inf = 0x3f3f3f3f, mod = 998244353;
const double eps = 1e-2;
const long double pi = acos(-1);
typedef long long LL;
typedef pair<LL, LL> PII;
typedef long double LD;
typedef unsigned long long ull;
const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();
int b[N];
int a[500][500];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t;
    //cin >> t;
    t = 1;
    while (t--) {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> b[i];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                cout << ((i * j + b[i] - i * i)%n+n)%n << ' ';
            }
            cout << endl;
        }
        
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1732. Find the Highest Altitude
709. To Lower Case
1688. Count of Matches in Tournament
1684. Count the Number of Consistent Strings
1588. Sum of All Odd Length Subarrays
1662. Check If Two String Arrays are Equivalent
1832. Check if the Sentence Is Pangram
1678. Goal Parser Interpretation
1389. Create Target Array in the Given Order
1313. Decompress Run-Length Encoded List
1281. Subtract the Product and Sum of Digits of an Integer
1342. Number of Steps to Reduce a Number to Zero
1528. Shuffle String
1365. How Many Numbers Are Smaller Than the Current Number
771. Jewels and Stones
1512. Number of Good Pairs
672. Richest Customer Wealth
1470. Shuffle the Array
1431. Kids With the Greatest Number of Candies
1480. Running Sum of 1d Array
682. Baseball Game
496. Next Greater Element I
232. Implement Queue using Stacks
844. Backspace String Compare
20. Valid Parentheses
746. Min Cost Climbing Stairs
392. Is Subsequence
70. Climbing Stairs
53. Maximum Subarray
1527A. And Then There Were K