← Back to Problems
Gaussian Quadrature
Hard standard Numerical Methods
Time limit: 4 s per test  ·  Memory: 256 MB

For real parameters alpha >= 0 and beta > 1, consider the weight function

w(x) = x^alpha exp(-x^beta) on (0, infinity).

The n-point Gaussian quadrature rule for this weight is the unique choice of nodes x_1 < ... < x_n in (0, infinity) and positive weights w_1, ..., w_n such that

integral from 0 to infinity of f(x) w(x) dx = w_1 f(x_1) + ... + w_n f(x_n)

holds exactly for every polynomial f of degree at most 2n - 1.

Given alpha, beta and n, output the rule.

Input

One line with alpha, beta (each with at most 6 digits after the decimal point) and the integer n.

Output

n lines. Line i contains x_i and w_i, nodes in increasing order, each with absolute error at most 1e-10 or relative error at most 1e-7.

Constraints

0 <= alpha <= 5

1.1 <= beta <= 4

1 <= n <= 20

Scoring

This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.

Numeric answers are accepted if they are within an absolute tolerance of 1e-10 or a relative tolerance of 1e-07 of the expected value.

Examples

input
1.0 2.0 3
output
0.37813462343448623 0.18961964883835322
1.0862473525771112 0.27395311770345276
2.0268039148847183 0.03642723345819414
input
0.5 1.5 8
output
0.12723205095023052 0.08505413608252807
0.4866967115212445 0.23016724097900004
1.0435949028224707 0.22743946901103657
1.7745936676821876 0.10200616399291837
2.672710618598501 0.02036356714153065
3.7513302073279813 0.0015985159316827032
5.058914529912156 3.744544762342451e-05
6.746078310897918 1.2808034728544058e-07
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2