运用了矩阵快速幂的方法
#include<iostream>
#include<cstring>
typedef long long ll;
const int mod = 1000000007;
using namespace std;
ll base[3][3];
ll ans[3][3];
ll temp[3][3];
//初始化
void NO(ll a,ll b)
{
memset(base, 0, sizeof base);
memset(ans, 0, sizeof ans);
base[1][1] = a;
base[1][2] = 1;
base[2][1] = b;
ans[1][1] = 1;
ans[1][2] = 0;
}
//矩阵乘法
void mul(ll a[3][3], ll b[3][3])
{
memset(temp, 0, sizeof temp);
for (ll i = 1; i <= 2; i++)
for (ll j = 1; j <= 2; j++)
for (ll k = 1; k <= 2; k++)
temp[i][j] = (temp[i][j] + a[i][k] * b[k][j] % mod) % mod;
for (ll i = 1; i <= 2; i++)
for (ll j = 1; j <= 2; j++)
a[i][j] = temp[i][j] % mod;
}
void fun(ll n)
{
while (n) {
if (n & 1)
mul(ans, base);
mul(base, base);
n >>= 1;
}
}
int main()
{
ll n, a, b;
cin >> n >> a >> b;
if (n <= 1) {
cout << n;
return 0;
}
NO(a, b);
fun(n - 1);
ll tmp = ans[1][1] % mod;
cout << tmp;
}