Links: http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=115
Originally, this is a problem, but we can extract methods from it.
Analysis and understanding of the topic:
1. For the problem, the data range of n is given: 1 < n < 1 000 000 000 000 violent solution, plus multiple sets of data, it is obvious that the rhythm of time overrun is needed. So we need to use our brains patiently for analysis.
2. For this problem, we can't directly come up with a good and efficient algorithm through the analysis of the problem, so the answer or the law of solution must have inextricable connection with n, so we can boldly make a table to find the internal connection.
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn=90+5; //Define the size of the array, usually declare several more than the capacity
const int maxm=90; //Meter capacity
unsigned long long a[maxn]; //An array of Fibonacci sequences
unsigned long long Fib(int n)
{
if(a[n]!=0&&n>0) return a[n];
return a[n]=Fib(n-1)+Fib(n-2);
}
int main()
{
a[1]=1;a[2]=1;
Fib(maxm);
//for(int i=1;i<maxm;i++) {cout<<i<<' ';cout<<a[i]<<' ';if(a[i]%3==0) cout<<3<<' ';if(a[i]%4==0) cout<<4<<' ';if(a[i]%12==0)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
for(int i=1;i<maxm;i++)
{
if(a[i]%3==0) cout<<i<<' '<<a[i]<<endl; //Output satisfaction%3 n The term of and Fibonacci number of
// if(a[i]%4==0) cout<<i<<' '<<a[i]<<endl; //Output satisfaction%4 n The term of and Fibonacci number of
// if(a[i]%12==0) cout<<i<<' '<<a[i]<<endl;//Output satisfaction%12 n The term of and Fibonacci number of
}
return 0;
}
if(a[i]%3==0) cout<<i<<' '<<a[i]<<endl; //Output items and Fibonacci numbers satisfying% 3 n
4 3
8 21
12 144
16 987
20 6765
24 46368
28 317811
32 2178309
36 14930352
40 102334155
44 701408733
48 4807526976
52 32951280099
56 225851433717
60 1548008755920
64 10610209857723
68 72723460248141
72 498454011879264
76 3416454622906707
80 23416728348467685
84 160500643816367088
88 1100087778366101931
if(a[i]%4==0) cout<<i<<' '<<a[i]<<endl; //Output items and Fibonacci numbers satisfying% 4 n
6 8
12 144
18 2584
24 46368
30 832040
36 14930352
42 267914296
48 4807526976
54 86267571272
60 1548008755920
66 27777890035288
72 498454011879264
78 8944394323791464
84 160500643816367088
if(a[i]%12==0) cout<<i<<' '<<a[i]<<endl;//Output items and Fibonacci numbers satisfying% 12 n
12 144
24 46368
36 14930352
48 4807526976
60 1548008755920
72 498454011879264
84 160500643816367088
At the test capacity of 90, we found that:
%If (n% 4 = = 0) a [i]% 3 = = 0;
%If (n% 6 = = 0) a [i]% 4 = = 0;
%If (n% 12 = = 0) a [i]% 12 = = 0 is established;
The final procedure is as follows:
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int n;
while(cin >> n){
if(n%12==0)
cout << "YES" << endl;
else{
if(n%4==0)
cout << "3" << endl;
else{
if(n%6==0)
cout << "4" << endl;
else
cout << "NO" << endl;
}
}
}
return 0;
}