Beginner Contest 178"/>
AtCoder Beginner Contest 178
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300300 points
Problem Statement
How many integer sequences A1,A2,…,ANA1,A2,…,AN of length NN satisfy all of the following conditions?
- 0≤Ai≤90≤Ai≤9
- There exists some ii such that Ai=0Ai=0 holds.
- There exists some ii such that Ai=9Ai=9 holds.
The answer can be very large, so output it modulo 109+7109+7.
Constraints
- 1≤N≤1061≤N≤106
- NN is an integer.
Input
Input is given from Standard Input in the following format:
NN
Output
Print the answer modulo 109+7109+7.
Sample Input 1 Copy
Copy
2
Sample Output 1 Copy
Copy
2
Two sequences {0,9}{0,9} and {9,0}{9,0} satisfy all conditions.
Sample Input 2 Copy
Copy
1
Sample Output 2 Copy
Copy
0
Sample Input 3 Copy
Copy
869121
Sample Output 3 Copy
Copy
2511445
思路:
A = 不包含9的 = 9^n
B = 不包含0的 = 9^n
AB = 不包含9的也不包含0的 = 8^n
A + B = 不包含9的或不包含0的 A+ B = A + B - AB
全部的10^n
既包含9也包含0的 = 10^n - (A + B) = 10^n - 9^n - 9^n + 8^n
code:
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 100003
#define mod 1000000007
#define pb push_back
#define x first
#define y second
#define ull unsigned long long
#define ll long long
using namespace std;
ll n;
ll powmod(ll x)
{ll res = 1;for(int i = 1;i <= n;i++){res = res * x % mod ;}return res;
}
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);cin >> n;ll ans = powmod(10) - powmod(9) - powmod(9) + powmod(8);ans = ans % mod;ans = (ans + mod) % mod;cout << ans << endl;return 0;
}
更多推荐
AtCoder Beginner Contest 178
发布评论