回复 楼主 好烦、
程序代码:
#include<stdio.h> int main(void) { int N,f1,f2,i,A; f1 = 1; f2 = 1; scanf("%d",&N); if(N > 2) { for(i = 3;i <= N;i++) { A = f1 + f2; f1 = f2; f2 = A; } printf("%d\n",A); } else if(N <= 2) printf("1\n"); return 0; }
#include <stdio.h> int main(void) { unsigned n; scanf( "%d", &n ); unsigned a=0, b=1; for( unsigned i=0; i!=n; ++i ) { unsigned c = a+b; a = b; b = c%2000000003; } printf( "%u", a%2000000003 ); }
#include <stdio.h> unsigned long long fibonacci( unsigned n ) { // a *= b #define MUL(a,b) do {\ unsigned long long t00 = (a##00*b##00+a##01*b##10)%2000000003;\ unsigned long long t01 = (a##00*b##01+a##01*b##11)%2000000003;\ unsigned long long t10 = (a##10*b##00+a##11*b##10)%2000000003;\ unsigned long long t11 = (a##10*b##01+a##11*b##11)%2000000003;\ a##00=t00, a##01=t01, a##10=t10, a##11=t11;\ } while(0) unsigned long long r00=1,r01=0,r10=0,r11=1; for( unsigned long long v00=0,v01=1,v10=1,v11=1; n!=0; n/=2 ) { if( n%2 == 1 ) MUL(r,v); // r*=v MUL(v,v); // v*=v; } return r01%2000000003; #undef MUL } int main( void ) { unsigned n; scanf( "%u", &n ); printf( "%llu\n", fibonacci(n) ); }