Potential energy
Practice
3 (2 votes)
Algorithms
Approved
Fft
Fast fourier transform
Medium
Problem
92% Success 1956 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

There are N electrons present in the coordinate plane. For each electron, you have been given three values \(X_i, Y_i\) and \(K_i\), where \(X_i\) and \(Y_i\) denotes X coordinate and Y coordinates of electron in the plane and \(K_i\) denotes the self - potential energy of \(i^{th}\) electron if other electron weren't present in the plane. You have to calculate potential energy of this system of electrons which is given by following formula: \(\sum_{i=1}^{i=N} \sum_{j=1}^{j=N} K_i * K_j * DIST(i,j)\)
\(DIST(i,j)\) denotes floor of euclidean distance between \(i^{th}\) and \(j^{th}\) electron. That is, \(DIST(i,j) = \lfloor \sqrt {(X_{i}-X_{j})^{2} + (Y_{i}-Y_{j})^{2}} \rfloor\) where \( \lfloor \rfloor\) denotes floor function.

Since electrons are very small in size, there can be more than one electron present at a point.

INPUT:
First line will consists of integer N denoting total number of electrons. Next N lines will consists of three integers \(X_i, Y_i, K_i\).

OUTPUT:
Output potential energy of this system of electrons. Since output can be large print it modulo \(10^9+7\).

CONSTRAINTS:
\(1 \le N \le 10^6\)
\(1 \le X_i, Y_i, K_i \le 500\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
3 votes
Tags:
AlgorithmsConvolutionFast Fourier transformMedium
Points:50
11 votes
Tags:
Divide-and-conquer algorithmFast Fourier transformGenerating FunctionsMedium