1 solutions
-
1
思路一
直接无脑快速幂,求就完事,然后注意一下数据大于等于27的时候
思路二
直接打标,我们能发现当n大于等于27的时候我们直接输出134217727即可,这是由于这个模数是2的幂,感兴趣可以去试一试
Code
#include<bits/stdc++.h> using namespace std; #define ll long long ll mod = 134217728;//27 ll ksm(ll a,ll b) { ll ans = 1; for(;b;b>>=1LL) { if(b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } int main() { ll n ; scanf("%lld",&n); ll ans = (ksm(2LL,n)-1+mod)%mod; printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long ll mod = 134217728;//27 int main() { ll n ; scanf("%lld",&n); if(n >= 27) puts("134217727"); else{ ll ans = 1; while(n--) ans *= 2; printf("%lld\n",ans-1); } return 0; }
- 1
Information
- ID
- 268
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- # Submissions
- 134
- Accepted
- 23
- Uploaded By