Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大牛们帮我看看错哪了

Posted by 4053040 at 2010-02-04 15:24:36 on Problem 3070
#include<iostream>
using namespace std;

int n;
void xiangcheng_fib(unsigned long a, unsigned long b, unsigned long c, unsigned long d)
{
	int fib(int n, unsigned long a, unsigned long b, unsigned long c, unsigned long d);
	fib(n / 2, (a * a + b * c) % 10000, (a * b + b * d) % 10000, (a * c + c * d) % 10000, (c * b + d * d) % 10000);
}

void jianyi_fib(unsigned long a, unsigned long b, unsigned long c, unsigned long d)
{
	int fib(int n, unsigned long a, unsigned long b, unsigned long c, unsigned long d);
	fib(n - 1, (a + b) % 10000, a, (c + d) % 10000, c);
}

int fib(int n, unsigned long a, unsigned long b, unsigned long c, unsigned long d)
{
	if(n == 0) return 0;
	else if(n == 1) return b;
	else if(n % 2 == 0) 
		xiangcheng_fib(a, b, c, d);
	else  //n % 2 != 0
		jianyi_fib(a, b, c, d);
}


int main()
{
	while(cin >> n) {
		if(n == -1) break;
		cout << fib(n, 1, 1, 1, 0) % 10000 << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator