Submission #19980

# Submission time Handle Problem Language Result Execution time Memory
19980 2016-02-25T08:07:38 Z inspire12 괄호 (kriii4_R) C++
0 / 100
0 ms 1208 KB
#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
1 Incorrect 0 ms 1208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -