답안 #407224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407224 2021-05-18T16:21:43 Z luka1234 Rack (eJOI19_rack) C++14
100 / 100
6 ms 204 KB
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;  
ll p=1000000007;
ll logpow(ll v,ll e){
	if(e==0)
	   return 1;
	else{
		if(e%2==0){
			ll ans=logpow(v,e/2);
			ans%=p;
			ans=ans*ans;
			ans%=p;
			return ans;
		}
		else{
			ll ans=logpow(v,e/2);
			ans%=p;
			ans=ans*ans;
			ans%=p;
			ans*=v;
			ans%=p;
			return ans;
		}
	}
}
int main(){
    ll n,m;
    cin>>n>>m;
    ll v=1,cnt=0;
    while(cnt!=n){
    	if(m%2==1)
           v=2*v;
        else
           v=2*v+1;
        v%=p;
        if(m%2==0)
           m=m/2;
        else
           m=m/2+1;
        cnt++;
	}
	ll pow=logpow(2,n)-1;
	pow%=p;
	ll ans=v-pow;
	if(ans<0)
	   ans=p-abs(ans);
	cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 6 ms 204 KB Output is correct