This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
using namespace std;
vector<pair<long long, long long> > v;
unsigned long long res = 1;
unsigned long long res2 = 1;
unsigned long long res3 = 1;
pair <long long , long long > p;
int main() {
int n, s; long long i;
scanf("%d %d", &n, &s);
if (s == 1) {
long long res = (n + 1) / 2 + n;
for (int i = 1; i <= n - 2; i++) {
res += (n - 1);
}
printf("%lld", res % 1000000007);
}
else {
long long y = s;
p.first = n;
p.second = 1;
v.push_back(p);
long long e = (n + 1) / 2;
for (i = 2; i <= e; i *= 2) {
p.first = (s % 1000000007) *(s % 1000000007) % 1000000007;
s = p.first;
p.second = i;
v.push_back(p);
} long long a; int temp = (n - 1) - e; int temp2 = e;
while (e > 0 && !v.empty()) {
a = v[v.size() - 1].second;
if (e - a >= 0) res = ((res % 1000000007) * (v[v.size() - 1].first % 1000000007)) % 1000000007, e -= a;
v.pop_back();
}
res3 = res;
if (n > 2) {
res = res;
for (int i = temp; i > 0; i--) {
res2 = ((res2 % 1000000007) * (y % 1000000007)) % 1000000007;
}
for (int i = n - 2; i > 1; i--) {
res2 = ((res2 % 1000000007) * (y % 1000000007)) % 1000000007;
}
}
else { res2 = 0; }
for (int i = temp + 1; i > 0; i--) {
res3 = ((res3 % 1000000007) * (y % 1000000007)) % 1000000007;
}
printf("%lld", res + res2 + res3);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |