// Łukasz Proksa, Silesian University of Technology, Poland // Potyczki Algorytmiczne 2015 // Task "Fibbonacci" // O (1 mln) #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<LL> VLL; typedef pair<int, int> PII; typedef vector<PII> VPII; #define LET(k, val) __typeof(val) k = (val) #define FOR(i, b, e) for(LET(i,b); i <= (e); ++i) #define FORD(i, b, e) for(LET(i,b); i >= (e); --i) #define REP(i, n) for(int i = 0; i < (n); ++i) #define SIZE(c) ((int)(c).size()) #define ALL(c) (c).begin(), (c).end() #define FOREACH(i, c) for(LET(i,(c).begin()); i != (c).end(); ++i) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ST first #define ND second #define PB push_back #define MP make_pair #define COUT(c) {cout<<SIZE(c)<<":{";FOREACH(i,c){cout<<*i<<",";}cout<<"}";} static const int K = 1e6; // 1 mln static const int M = 1e5; // 100 tys int g(int a) { int i = 1; while (a > 0) { a /= 10; i *= 10; } return i; } int main() { LL a; cin>>a; int m = (int)(a % (LL)M); bool small = (a < M); int mod = (small ? g(m) : M); int result = -1; int f1 = 1; int f2 = 1; REP(i, K) { if (f2 % mod == m) { result = f2; break; } int tmp = f2; f2 = (f1 + f2) % M; f1 = tmp; } if (result > 0) { if (small) { cout<<result<<endl; } else { cout<<a<<endl; } } else { cout<<"NIE"<<endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | // Łukasz Proksa, Silesian University of Technology, Poland // Potyczki Algorytmiczne 2015 // Task "Fibbonacci" // O (1 mln) #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<LL> VLL; typedef pair<int, int> PII; typedef vector<PII> VPII; #define LET(k, val) __typeof(val) k = (val) #define FOR(i, b, e) for(LET(i,b); i <= (e); ++i) #define FORD(i, b, e) for(LET(i,b); i >= (e); --i) #define REP(i, n) for(int i = 0; i < (n); ++i) #define SIZE(c) ((int)(c).size()) #define ALL(c) (c).begin(), (c).end() #define FOREACH(i, c) for(LET(i,(c).begin()); i != (c).end(); ++i) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ST first #define ND second #define PB push_back #define MP make_pair #define COUT(c) {cout<<SIZE(c)<<":{";FOREACH(i,c){cout<<*i<<",";}cout<<"}";} static const int K = 1e6; // 1 mln static const int M = 1e5; // 100 tys int g(int a) { int i = 1; while (a > 0) { a /= 10; i *= 10; } return i; } int main() { LL a; cin>>a; int m = (int)(a % (LL)M); bool small = (a < M); int mod = (small ? g(m) : M); int result = -1; int f1 = 1; int f2 = 1; REP(i, K) { if (f2 % mod == m) { result = f2; break; } int tmp = f2; f2 = (f1 + f2) % M; f1 = tmp; } if (result > 0) { if (small) { cout<<result<<endl; } else { cout<<a<<endl; } } else { cout<<"NIE"<<endl; } return 0; } |