2个回答
展开全部
#include<iostream>
#include<stdio.h>
using namespace std;
#define mdu 1000000007;
#define N 15
struct matrix
{
__int64 a[N][N];
};
matrix chu,die;
matrix mul(matrix a1,matrix a2,int ii)
{
int i,j,k;
matrix c;
for(i=1;i<=ii;i++)
for(j=1;j<=ii;j++)
{
c.a[i][j]=0;
for(k=1;k<=ii;k++)
c.a[i][j]+=a1.a[i][k]*a2.a[k][j]%mdu;
c.a[i][j]%=mdu;
}
return c;
}
void qmi(__int64 nn)
{
while(nn>0)
{
if(nn%2==1) chu=mul(chu,die,2);
die=mul(die,die,2);
nn=nn>>1;
}
}
int main()
{
__int64 n;
while(scanf("%I64d",&n)!=EOF)
{
chu.a[1][1]=1; chu.a[1][2]=1;
chu.a[2][1]=0; chu.a[2][2]=0;
die.a[1][1]=1; die.a[1][2]=1;
die.a[2][1]=1; die.a[2][2]=0;
if(n!=1 || n!=2) qmi(n-2);
printf("%The number is:%I64d\n",chu.a[1][1]);
}
return 0;
}
原创的哦
#include<stdio.h>
using namespace std;
#define mdu 1000000007;
#define N 15
struct matrix
{
__int64 a[N][N];
};
matrix chu,die;
matrix mul(matrix a1,matrix a2,int ii)
{
int i,j,k;
matrix c;
for(i=1;i<=ii;i++)
for(j=1;j<=ii;j++)
{
c.a[i][j]=0;
for(k=1;k<=ii;k++)
c.a[i][j]+=a1.a[i][k]*a2.a[k][j]%mdu;
c.a[i][j]%=mdu;
}
return c;
}
void qmi(__int64 nn)
{
while(nn>0)
{
if(nn%2==1) chu=mul(chu,die,2);
die=mul(die,die,2);
nn=nn>>1;
}
}
int main()
{
__int64 n;
while(scanf("%I64d",&n)!=EOF)
{
chu.a[1][1]=1; chu.a[1][2]=1;
chu.a[2][1]=0; chu.a[2][2]=0;
die.a[1][1]=1; die.a[1][2]=1;
die.a[2][1]=1; die.a[2][2]=0;
if(n!=1 || n!=2) qmi(n-2);
printf("%The number is:%I64d\n",chu.a[1][1]);
}
return 0;
}
原创的哦
2013-04-18
展开全部
#include <stdio.h>
main() {
unsigned long Fibonacci[100] = {0,1};
char i,n;
printf("\n第几项:");
scanf("%d",&n);
if(n > 40) n = 40;
for(i = 2;i <= n;i++) Fibonacci[i] = Fibonacci[i - 2] + Fibonacci[i - 1];
printf("斐波那契数列的第%lu项是:%lu。\n\n",n,Fibonacci[n - 1]);
}
main() {
unsigned long Fibonacci[100] = {0,1};
char i,n;
printf("\n第几项:");
scanf("%d",&n);
if(n > 40) n = 40;
for(i = 2;i <= n;i++) Fibonacci[i] = Fibonacci[i - 2] + Fibonacci[i - 1];
printf("斐波那契数列的第%lu项是:%lu。\n\n",n,Fibonacci[n - 1]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询