Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Test1.cpp : Defines the entry point for the console application.
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include <cstdio>
- #include <cassert>
- #define A_MILLI 1000 * 1000
- typedef long long ll_t;
- using namespace std;
- vector<int> euler_tot(const ll_t m) {
- vector<int> tot(m + 1, 0);
- tot[1] = 1;
- for (ll_t p = 2; p <= m; ) {
- for (ll_t pk = p; pk <= m; pk += p) {
- if (tot[pk] == 0) tot[pk] = 1;
- tot[pk] *= (p - 1);
- }
- for (ll_t pp = p * p; pp <= m; pp *= p)
- for (ll_t pk = pp; pk <= m; pk += pp)
- tot[pk] *= p;
- do ++p;
- while (p <= m && tot[p] != 0);
- }
- return tot;
- }
- inline string itos(const int n) {
- }
- inline bool isPerm(const string& a, const string& b) {
- if (a.length() != b.length()) return false;
- int cnt[10] = { 0 };
- for (int i = 0, n = a.length(); i < n; ++i)
- cnt[a[i] - '0']++;
- for (int i = 0, n = b.length(); i < n; ++i)
- if ( (--cnt[b[i] - '0']) < 0)
- return false;
- return true;
- }
- inline bool isLess(const ll_t a, const ll_t b, const ll_t c, const ll_t d) {
- return b * c - d * a > 0;
- }
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <winbase.h>
- int main2() {
- const int max = 10 * A_MILLI;
- vector<int> tot = euler_tot(max);
- int bestn; double bestr = 1e10;
- #pragma omp parallel for schedule(static, 12)
- for (int n = 8 * A_MILLI; n <= max; ++n) {
- char ca[25], cb[25];
- sprintf(ca, "%d", n);
- sprintf(cb, "%d", tot.at(n));
- string sa(ca), sb(cb);
- const double r = n / double(tot[n]);
- #pragma omp critical
- if (isPerm(sa, sb) && (r < bestr))
- bestn = n, bestr = r;
- }
- cout << bestn << endl;
- return 0;
- }
- int main()
- {
- int count,a;
- LARGE_INTEGER ticksPerSecond;
- LARGE_INTEGER tick; // A point in time
- LARGE_INTEGER start_ticks, end_ticks, cputime;
- if (!QueryPerformanceFrequency(&ticksPerSecond))
- printf("\tno go QueryPerformance not present");
- printf ("\tfreq test: %I64Ld ticks/sec\n",ticksPerSecond );
- // what time is it?
- if (!QueryPerformanceCounter(&tick) ) printf("no go counter not installed");
- printf ("\QueryPerformanceCounter testpoint : %I64Ld ticks\n",tick);
- QueryPerformanceCounter(&start_ticks);
- main2();
- QueryPerformanceCounter(&end_ticks);
- cputime.QuadPart = end_ticks.QuadPart- start_ticks.QuadPart;
- printf ("\tElapsed CPU time test: %.9f sec ticks %d\n",
- ((float)cputime.QuadPart/(float)ticksPerSecond.QuadPart),cputime.QuadPart);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement