【找规律】#64 A. Cookies

A. Cookies
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square k × k in size, divided into blocks 1 × 1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie k in size. Fangy also has a box with a square base 2n × 2n, divided into blocks 1 × 1in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4respectively on the figure:

To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end.

Input

The first line contains a single integer n (0 ≤ n ≤ 1000).

Output

Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106 + 3.

Sample test(s)
input
3
output
9
Note

If the box possesses the base of 23 × 23 (as in the example), then the cookies will be put there in the following manner:



细心的大家应该可以发现,这是个从2开始公比为3的等比数列。

看不出来的话注意看图,把每张图分成四个象限,每一个n都是n+1的图的第三象限的部分~

既然知道了规律,取模的时候注意一下 a%b要写成 (a+b)%b 的形式即可~

#include <cstdio>
#include <string>
#include <cstring> 
#include <iostream>
using namespace std;

int main()
{
	int n,ans=1;	cin>>n;
	const int mod=(int)1e6+3;
	for(int i=2;i<=n;i++) 
	{
		ans*=3;
		ans=(ans+mod)%mod;
	}
	cout<<ans; 
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖果天王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值