25 lines
426 B
C#
25 lines
426 B
C#
using System;
|
|
|
|
class GeometricProgression : IProgression
|
|
{
|
|
private int p0;
|
|
private int q;
|
|
|
|
public GeometricProgression(int p0, int q)
|
|
{
|
|
this.p0 = p0;
|
|
this.q = q;
|
|
}
|
|
|
|
public int GetElement(int k)
|
|
{
|
|
return p0 * (int)Math.Pow(q, k - 1);
|
|
}
|
|
|
|
public int Sum(int n)
|
|
{
|
|
if (q == 1) return p0 * n;
|
|
return p0 * (int)((Math.Pow(q, n) - 1) / (q - 1));
|
|
}
|
|
}
|