热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【找规律】#64A.Cookies

A.Cookiestimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputsta


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
#include
#include
#include
using namespace std;int main()
{int n,ans&#61;1; cin>>n;const int mod&#61;(int)1e6&#43;3;for(int i&#61;2;i<&#61;n;i&#43;&#43;) {ans*&#61;3;ans&#61;(ans&#43;mod)%mod;}cout<}







推荐阅读
author-avatar
lb小小凡人
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有