#include<iostream>
using namespace std;
unsigned long long gcd(unsigned long long m, unsigned long long n) {
if(n == 0)
return m;
else
return gcd(n, m % n);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
unsigned long long F[10050];
F[0] = (unsigned long long)0;
F[1] = (unsigned long long)1;
for(int i=2; i<10050; i++)
F[i] = (unsigned long long)F[i-1] + (unsigned long long)F[i-2];
int a, b;
while(cin >> a >> b)
{
cout << gcd(F[a], F[b]) << '\n';
}
return 0;
}
各種改法都錯了,感覺測資有錯
WA (line:3)
#include
using namespace std;
unsigned long long gcd(unsigned long long m, unsigned long long n) {
if(n == 0)
return m;
else
return gcd(n, m % n);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
unsigned long long F[10050];
F[0] = (unsigned long long)0;
F[1] = (unsigned long long)1;
for(int i=2; i<10050; i++)
F[i] = (unsigned long long)F[i-1] + (unsigned long long)F[i-2];
int a, b;
while(cin >> a >> b)
{
cout << gcd(F[a], F[b]) << '\n';
}
return 0;
}
各種改法都錯了,感覺測資有錯
WA (line:3)
答案不會超過unsigned long long,不代表這種暴力解的運算過程中不會超過unsigned long long