1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #include <stack> 9 #include <map> 10 #include <set> 11 #include <cmath> 12 #include <cctype> 13 #include <ctime> 14 15 using namespace std; 16 17 #define REP(i, n) for (int i = 0; i < (n); ++i) 18 #define eps 1e-9 19 20 typedef long long ll; 21 typedef pair<int, int> pii; 22 23 const int INF = 0x7fffffff; 24 const int maxn = 1e7 + 10; 25 ll ans = 0; 26 map<ll, ll> ans_t, pre; 27 28 ll cal(ll x) { 29 ll ret = 1, x_t = x, t = x; pre[x] = x; 30 while (x != 1) { 31 if (ans_t.count(x)) { ans_t[x_t] = ret + ans_t[x] - 1; break; } 32 if (x % 2 == 0) { x /= 2; } else { x = x * 3 + 1; } 33 pre[x] = t; t = x; 34 ++ret; 35 } 36 if (x == 1) { ans_t[x_t] = ret; } 37 for (ll i = pre[x], j = 1; i != x_t; i = pre[i], ++j) { 38 ans_t[i] = ans_t[x] + j; 39 } 40 return ans_t[x_t]; 41 } 42 43 int main() { 44 #ifdef __AiR_H 45 // freopen("in.txt", "r", stdin); 46 // freopen("out.txt", "w", stdout); 47 #endif // __AiR_H 48 ll t; ll my_ans; 49 for (int i = 1; i < 1000000; ++i) { 50 t = cal(i); 51 if (t > ans) { ans = t; my_ans = i; } 52 } 53 printf("%I64d ", my_ans); 54 #ifdef __AiR_H 55 printf("Time used = %.2fs ", (double)clock() / CLOCKS_PER_SEC); 56 #endif // __AiR_H 57 return 0; 58 }
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #include <stack> 9 #include <map> 10 #include <set> 11 #include <cmath> 12 #include <cctype> 13 #include <ctime> 14 15 using namespace std; 16 17 #define REP(i, n) for (int i = 0; i < (n); ++i) 18 #define eps 1e-9 19 20 typedef long long ll; 21 typedef pair<int, int> pii; 22 const int maxn = 1e7; 23 const ll INF = 1e18; 24 int prime_cnt = 0; 25 int prime[maxn]; 26 bool vis[maxn]; 27 ll ans = INF; 28 29 void init() { 30 for (int i = 2; i < maxn; ++i) { 31 if (!vis[i]) { 32 prime[prime_cnt++] = i; 33 for (int j = i; j < maxn; j += i) { vis[j] = true; } 34 } 35 } 36 } 37 bool check(ll a, ll b) { return a * 94744 < b * 15499; } 38 ll euler(int x) { 39 ll ret = x; 40 for (int i = 0; prime[i] * prime[i] <= x; ++i) { 41 if (x % prime[i] == 0) { 42 ret = ret / prime[i] * (prime[i] - 1); x /= prime[i]; 43 while (x % prime[i] == 0) { x /= prime[i]; } 44 } 45 } 46 if (x != 1) { ret = ret / x * (x - 1); } 47 return ret; 48 } 49 50 // 6469693230 51 int main() { 52 #ifdef __AiR_H 53 freopen("in.txt", "r", stdin); 54 freopen("out.txt", "w", stdout); 55 #endif // __AiR_H 56 init(); ll t = 1; 57 for (int i = 2; i < prime[9]; ++i) { 58 t = 1ll * 223092870 * i; 59 if (check(euler(t), t - 1)) { ans = t; break; } 60 } 61 printf("%I64d ", ans); 62 #ifdef __AiR_H 63 printf("Time used = %.2fs ", (double)clock() / CLOCKS_PER_SEC); 64 #endif // __AiR_H 65 return 0; 66 }
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #include <queue> 7 #include <vector> 8 #include <stack> 9 #include <map> 10 #include <set> 11 #include <cmath> 12 #include <cctype> 13 #include <ctime> 14 15 using namespace std; 16 17 #define REP(i, n) for (int i = 0; i < (n); ++i) 18 #define eps 1e-9 19 20 typedef long long ll; 21 typedef pair<int, int> pii; 22 const int maxn = 210; 23 int key[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 24 ll ans = 0; 25 set<ll> s; 26 27 void print() { 28 for (int i = 0; i < 9; ++i) { printf("%d ", key[i]); } printf(" "); 29 } 30 int cal_tt(int l, int r) { 31 int ret = 0; 32 for (int i = l; i < r; ++i) { ret = ret * 10 + key[i]; } 33 return ret; 34 } 35 void cal_t(int x, int y) { 36 ll t1 = cal_tt(0, x), t2 = cal_tt(x, y), t3 = cal_tt(y, 9); 37 if (t1 * t2 == t3) { 38 if (s.find(t3) != s.end()) { return; } 39 printf("%I64d %I64d %I64d ", t1, t2, t3); s.insert(t3); 40 ans += t3; 41 } 42 } 43 void cal() { 44 for (int i = 1; i <= 7; ++i) { 45 for (int j = i + 1; j <= 8; ++j) { 46 cal_t(i, j); 47 } 48 } 49 } 50 51 int main() { 52 #ifdef __AiR_H 53 freopen("in.txt", "r", stdin); 54 freopen("out.txt", "w", stdout); 55 #endif // __AiR_H 56 do { 57 cal(); 58 // print(); 59 } while (next_permutation(key, key + 9)); 60 printf("%I64d ", ans); 61 #ifdef __AiR_H 62 printf("Time used = %.2fs ", (double)clock() / CLOCKS_PER_SEC); 63 #endif // __AiR_H 64 return 0; 65 }