long long divisor(long long a,long long b)
{
long long c;
while(a%b!=0)
{
c=a%b;
a=b,b=c;
}
return c;
}
int main()
{
int f[15]={1,1,2,3,5,8,13,21,34,55,89,144,233,377,610};
int t;
long long a,b;
scanf(“%d”,&t);
int i=0;
int first=1;
for(i=0;i<t;i++)
{
if(first==0)
{
printf(“\n”);
}
int max,j;
scanf(“%d”,&max);
a=f[2],b=f[1];
for(j=1;j<max;j++)
{
a=af[j+1]+bf[j+2],b*=f[j+1];
a/=divisor(a,b),b/=divisor(a,b);
}
printf(“%I64d/%I64d”,a,b);
first=0;
}
}
test input:
13
1
2
3
4
5
6
7
8
9
10
11
12
13
test output
2/1
7/2
31/6
203/30
1007/240
18131/3120
162277/65520
4560509/2227680
89818303/122522400
25637054567/10904493600
43281131017/1570247078400
602067652083761/365867569267200
34627594006813069/137932073613734400
楼上数据有误吧:
input:
1
2
3
4
5
6
7
8
9
10
11
12
13
output:
2/1
7/2
31/6
203/30
1007/120
15611/1560
42319/3640
819523/61880
10116217/680680
998361233/60580520
19734909839/1090449360
5009333401207/254074700880
157192635368603/7368166325520
y wa?
代码不大好看…
include
long long divisor(long long a,long long b)
{
long long c;
while(a%b!=0)
{
c=a%b;
a=b,b=c;
}
return c;
}
int main()
{
int f[15]={1,1,2,3,5,8,13,21,34,55,89,144,233,377,610};
int t;
long long a,b;
scanf(“%d”,&t);
int i=0;
int first=1;
for(i=0;i<t;i++)
{
if(first==0)
{
printf(“\n”);
}
int max,j;
scanf(“%d”,&max);
a=f[2],b=f[1];
for(j=1;j<max;j++)
{
a=af[j+1]+bf[j+2],b*=f[j+1];
a/=divisor(a,b),b/=divisor(a,b);
}
printf(“%I64d/%I64d”,a,b);
first=0;
}
}
test input:
13
1
2
3
4
5
6
7
8
9
10
11
12
13
test output
2/1
7/2
31/6
203/30
1007/240
18131/3120
162277/65520
4560509/2227680
89818303/122522400
25637054567/10904493600
43281131017/1570247078400
602067652083761/365867569267200
34627594006813069/137932073613734400
重做基本题
int a[16]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610};
ll gcd(ll s,ll d){
ll c=1;
while(s%d!=0){
c=s%d;
s=d;
d=c;
}
return c;
}
int main(int argc, char const argv[]){
int cas;
cin>>cas;
while(cas–){
int n;
cin>>n;
int r=n+1;
ll d=1;
for(int i=2;i<=r;i++)
d=a[i];
ll s=0;
for(int i=3;i<=r+1;i++)
s+=(a[i]*(d/a[i-1]));
ll c=gcd(s,d);
cout<<s/c<<”/”<<d/c<<endl;
}
return 0;
}