(code jam)Problem C. Numbers
来源:互联网 发布:新仙泥红枣桂圆 淘宝 编辑:程序博客网 时间:2024/06/12 02:14
Problem
In this problem, you have to find the last three digits before the decimal point for the number (3 + √5)n.
For example, when n = 5, (3 + √5)5 = 3935.73982... The answer is 935.
For n = 2, (3 + √5)2 = 27.4164079... The answer is 027.
Input
The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n.
Output
For each input case, you should output:
Case #X: Ywhere X is the number of the test case and Y is the last three integer digits of the number (3 + √5)n. In case that number has fewer than three integer digits, add leading zeros so that your output contains exactly three digits.
Limits
1 <= T <= 100
Small dataset
2 <= n <= 30
Large dataset
2 <= n <= 2000000000
Sample
题解:留着,等会写。先贴代码。不知道为什么提交不上去。运用了二项式原理。
因为是求(3+根号5)的n次方。我们可以添加一个(3-根号5)的n次方。其值远小于1,然后两者相加得s=a+b根号5.太麻烦了,不想写了。https://code.google.com/codejam/contest/32016/dashboard#s=a&a=2
#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <iostream>#include <cmath>#include <queue>#include <map>#include <stack>#include <list>#include <vector>using namespace std;#define DeBugstruct Mx{int a[3][3];}f,k;void Init(){k.a[1][1]=1;k.a[2][1]=0;k.a[1][2]=0;k.a[2][2]=1;}Mx mul(Mx x,Mx y){Mx z;int i,j,l;for (i=1;i<=2;i++)for (j=1;j<=2;j++){z.a[i][j]=0;for (l=1;l<=2;l++)z.a[i][j]=(z.a[i][j]+x.a[i][l]*y.a[l][j]) % 1000;}return z;}Mx ksm(Mx f,int n){if (n==1) return f;if (n % 2==0){Mx k1=ksm(f,n/2);return mul(k1,k1);}else return mul(f,ksm(f,n-1));}int main(){#ifdef DeBugfreopen("C-large-practice.in","r",stdin);freopen("output.out","w",stdout);#endifint T,n;scanf("%d",&T);f.a[1][1]=3;f.a[1][2]=5;f.a[2][1]=1;f.a[2][2]=3;for (int cas=1;cas<=T;cas++){scanf("%d",&n);Init();Mx ans=ksm(f,n);printf("#Case %d: %03d\n",cas,(2*ans.a[1][1]+999) % 1000);}return 0;}
0 0
- (code jam)Problem C. Numbers
- (code jam)Problem C. T9 Spelling
- Code Jam 2017 Qualification Round Problem B. Tidy Numbers
- Google code jam 2008 Round 1A(c.Numbers)题解
- Google Code Jam 2010 Qualification Round 2012 Problem B && C
- Code Jam 2010 Round 1A Problem C
- Code Jam 2010 Round 1B Problem C
- Google Code Jam 2014 Problem C. Minesweeper Master
- Google Code Jam 2014-Qualification Round-Problem C. Minesweeper Master
- Google Code Jam 2015 Qualification Round: Problem C. Dijkstra
- google code jam Round 1A 2015 Problem C. Logging
- code jam 2015 Problem C. Less Money, More Problems
- Code Jam 2017 Qualification Round Problem C. Bathroom Stalls
- Code Jam Problem D. GoroSort
- Google Code Jam 2014 -- C
- Google code jam Round1B Problem B
- Google code jam: Problem A. Store Credit
- Google code jam: Problem B. Reverse Words
- 学习MVC模式
- db2 用户及授权
- 每天要问自己的5个问题 你的答案是什么?
- MapReduce概念详解
- Rotate Image
- (code jam)Problem C. Numbers
- ini文件的保存,使用map更方便
- 菜鸟之学习STM32单片机(一)认识开发板
- oc语言 ARC机制的简单学习
- js基础知识(笔记)
- OCP-1Z0-051 第13题 q操作符
- 简单迷宫游戏1
- 使用CreatePen()创建自定义画笔
- 小熊维尼的12句超萌暖心格言