//author Karolina Miśkiewicz
#include<bits/stdc++.h>
using namespace std;
int tab[500007];
int len = 1000000007;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//ważne uwzględnij n < 4
int n, k;
cin >> n >> k;
if(n == 1)
{
cout << 0;
}
else if(n == 2)
{
cout << k;
}
else
{
long long w = 0, temp = 1;
for(int i = 0; i < n-3; i++)
{
temp *= k;
temp %= len;
}
w = (((temp*k)%len)*k)%len + (temp *(n-3))%len;
cout << w%len;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | //author Karolina Miśkiewicz #include<bits/stdc++.h> using namespace std; int tab[500007]; int len = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //ważne uwzględnij n < 4 int n, k; cin >> n >> k; if(n == 1) { cout << 0; } else if(n == 2) { cout << k; } else { long long w = 0, temp = 1; for(int i = 0; i < n-3; i++) { temp *= k; temp %= len; } w = (((temp*k)%len)*k)%len + (temp *(n-3))%len; cout << w%len; } } |
English