Codeforces Round #493 (Div. 1) C. Sky Full of Stars

C. Sky Full of Stars
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

On one of the planets of Solar system, in Atmosphere University, many students are fans of bingo game.

It is well known that one month on this planet consists of n2n2 days, so calendars, represented as square matrix nn by nn are extremely popular.

Weather conditions are even more unusual. Due to the unique composition of the atmosphere, when interacting with sunlight, every day sky takes one of three colors: blue, green or red.

To play the bingo, you need to observe the sky for one month — after each day, its cell is painted with the color of the sky in that day, that is, blue, green or red.

At the end of the month, students examine the calendar. If at least one row or column contains only cells of one color, that month is called lucky.

Let's call two colorings of calendar different, if at least one cell has different colors in them. It is easy to see that there are 3nn3n⋅n different colorings. How much of them are lucky? Since this number can be quite large, print it modulo 998244353998244353.

Input

The first and only line of input contains a single integer nn (1n10000001≤n≤1000000) — the number of rows and columns in the calendar.

Output

Print one number — number of lucky colorings of the calendar modulo 998244353998244353

Examples
input
Copy
1
output
Copy
3
input
Copy
2
output
Copy
63
input
Copy
3
output
Copy
9933
Note

In the first sample any coloring is lucky, since the only column contains cells of only one color.

In the second sample, there are a lot of lucky colorings, in particular, the following colorings are lucky:

While these colorings are not lucky:

思路:容斥,枚举行内一致以及列内一致的个个数,用二项式化简消掉一维,另一维直接枚举就行了。要用快速幂,nlogn,不知道官方题解O(n)是怎么做到的。

 

转载于:https://www.cnblogs.com/BIGTOM/p/9261964.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值