日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

發布時間:2023/11/29 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

B. Kolya and Tanya

Time Limit: 1 Sec ?

Memory Limit: 256 MB

題目連接

http://codeforces.com/contest/584/problem/B

Description

Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.

More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n?-?1, let the gnome sitting on the i-th place have ai coins. If there is an integer i (0?≤?i?<?n) such that ai?+?ai?+?n?+?ai?+?2n?≠?6, then Tanya is satisfied.

Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109?+?7. Two ways, a and b, are considered distinct if there is index i (0?≤?i?<?3n), such that ai?≠?bi (that is, some gnome got different number of coins in these two ways).

Input

A single line contains number n (1?≤?n?≤?105) — the number of the gnomes divided by three.

Output

Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109?+?7.

Sample Input

1

Sample Output

20

HINT

?

題意

給你一個環,環上有3n個點,每個點的權值可以是1-3,然后問你滿足a[i]+a[i+1]+a[i+2]!=6的方案有多少種

題解:

反面,a[i]+a[i+1]+a[i+2]=6的情況這三個數的取值一共有7種

那么答案就是 3^(3n) - 7^n就好了

代碼:

#include<stdio.h> #include<iostream> #include<math.h>using namespace std;#define mod 1000000007 long long quickpow(long long m,long long n,long long k) {long long b = 1;while (n > 0){if (n & 1)b = (b*m)%k;n = n >> 1 ;m = (m*m)%k;}return b; }int main() {long long n;cin>>n;cout<<(quickpow(3,3*n,mod) - quickpow(7,n,mod) + mod) % mod <<endl; }

?

總結

以上是生活随笔為你收集整理的Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。