Codeforces Round #324 (Div. 2) B
1 second
256 megabytes
standard input
standard output
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).
A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three.
Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109 + 7.
1
20
2
680
20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex):
题意: 输入一个n 3*n个位置 0~3n-1 每个位置的k等于(1,2,3)
若ai + ai + n + ai + 2n ≠ 6 则算做一种情况 问共有多少情况 % 1000000000+9
题解: 计算式子
ans1=3^3n%mod
ans2=7^n%mod
( ans1-ans2)%mod
若 ans1<ans2
则输出(ans1+mod-ans2)%mod
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<cmath>
#define ll __int64
#define pi acos(-1.0)
#define mod 1000000007
using namespace std;
ll n;
ll ans1,ans2;
ll quickmod(ll a,ll b)
{
ll sum=;
while(b)
{
if(b&)
sum=(sum*a)%mod;
b>>=;
a=(a*a)%mod;
}
return sum;
}
int main()
{
scanf("%I64d",&n);
ans1=quickmod(,*n)%mod;
ans2=quickmod(,n)%mod;
if(ans1>=ans2)
printf("%I64d\n",(ans1-ans2)%mod);
else
printf("%I64d\n",(ans1+mod-ans2)%mod);
return ;
}
Codeforces Round #324 (Div. 2) B的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
- 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/pro ...
- Codeforces Round #324 (Div. 2) A. Olesya and Rodion 水题
A. Olesya and Rodion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/p ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #324 (Div. 2) Dima and Lisa 哥德巴赫猜想
原题链接:http://codeforces.com/contest/584/problem/D 题意: 给你一个奇数,让你寻找三个以内素数,使得和为这个奇数. 题解: 这题嘛...瞎比搞搞就好,首先 ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
随机推荐
- spring-mybatis整合异常2
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' ...
- 如果理解&&运算符和各类数值的布尔值
&&(且运算符):表示二者都为true才为true: 短路原则:例如 : a && b; 当a为true时,程序无论如何都会走b,而不管b为true或者false ...
- vim编辑器使用习惯问题
Ubuntu中vi在编辑状态下方向键不能用,一按方向键盘就出ABCD,想插入个字母还非常麻烦,还有回格键不能删除等我们平时习惯的一些键都不能使用. 解决办法: 可以安装vim full版本,在full ...
- php扩展开发-资源类型
资源类型在内核中的结构 //zend_list.h typedef struct _zend_rsrc_list_entry { void *ptr; int type; int refcount; ...
- 转-Spark编程指南
Spark 编程指南 概述 Spark 依赖 初始化 Spark 使用 Shell 弹性分布式数据集 (RDDs) 并行集合 外部 Datasets(数据集) RDD 操作 基础 传递 Functio ...
- manjaro安装teamviewer后无法打开
点桌面快捷方式一闪而过 命令行运行提示 $ teamviewer /opt/teamviewer/tv_bin/script/tvw_exec:行7: /opt/teamviewer/logfiles ...
- perl语言入门总结-第4章-子程序
子程序定义和返回值 sub sum{ print "调用了子程序\n"; $a + $b; #后一行为返回值 } ; ; $s =∑ #34 调用子程序 子程序中的参数,参数固定( ...
- 适合pc端的移动拖拽,分享一下。
h5新加的特性拖拽事件,但是只适合PC端哦.不多说了上代码 <!DOCTYPE html> <html> <head> <title></titl ...
- 20145202马超 《Java程序设计》 实验一 实验报告
一.实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 二.实验内容 1.完成在Windows环境下对IDEA的配置: 2.实现求正整 ...
- ListView getChildCount 以及getChildAt 坑 误区指南
今天调试的时候,才知道. 原来listview 的 getChildCount 取得是当前可先的list item 的个数,而不是整个listview 的count. 整个listview 的数量应该 ...