「Poetize8」Divisible

描述 Description

设F[i]为斐波那契数列的第i项,F[1]=1,F[2]=1,F[i]=F[i-1]+F[i-2](i>=3)。

输入格式 InputFormat

输入包含若干行(不多于10行),以EOF结尾。每行包含两个整数a,b。

输出格式 OutputFormat

对于每一行输入,如果F[a]能整除F[b],输出1,否则输出0.

题解:

碰到一道一眼题。。。

貌似有结论:若y%x==1,则f[y]%f[x]==0?更强的结论是 gcd(f[x],f[y])=gcd(x,y)?

注意特判 1 和2

然后。。。

代码:

 1 #include<cstdio>
 2 
 3 #include<cstdlib>
 4 
 5 #include<cmath>
 6 
 7 #include<cstring>
 8 
 9 #include<algorithm>
10 
11 #include<iostream>
12 
13 #include<vector>
14 
15 #include<map>
16 
17 #include<set>
18 
19 #include<queue>
20 
21 #include<string>
22 
23 #define inf 1000000000
24 
25 #define maxn 500+100
26 
27 #define maxm 500+100
28 
29 #define eps 1e-10
30 
31 #define ll long long
32 
33 #define pa pair<int,int>
34 
35 #define for0(i,n) for(int i=0;i<=(n);i++)
36 
37 #define for1(i,n) for(int i=1;i<=(n);i++)
38 
39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
40 
41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
42 
43 #define mod 1000000007
44 
45 using namespace std;
46 
47 inline int read()
48 
49 {
50 
51     int x=0,f=1;char ch=getchar();
52 
53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
54 
55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
56 
57     return x*f;
58 
59 }
60 
61 int main()
62 
63 {
64 
65     freopen("input.txt","r",stdin);
66 
67     freopen("output.txt","w",stdout);
68     int x,y;
69 
70     while(cin>>x>>y)if(y%x==0||(x==2&&y==1))printf("1
");else printf("0
");
71 
72     return 0;
73 
74 }
View Code
原文地址:https://www.cnblogs.com/zyfzyf/p/4046560.html