Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- inline ll gcdZban(ll a, ll b) {
- while(b) b ^= a ^= b ^= a %= b;
- return a;
- }
- inline ll gcdT(ll a, ll b) {
- while(a&&b) a > b ? a %= b: b %= a;
- return a + b;
- }
- inline ll gcdA(ll a, ll b) {
- while(b) a %= b, swap(a, b);
- return a;
- }
- inline ll gcd(ll a, ll b) {
- return (b ? gcd(b, a % b): a);
- }
- ll gcd1(ll a, ll b) {
- while(b) {
- ll t = a % b;
- b = a;
- a = t;
- }
- return a;
- }
- int a[10000100];
- int b[10000100];
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(0);
- srand(time(0));
- int n = 10000000, i, g;
- double t;
- for(i = 0; i <= n; i++) {
- a[i] = rand() % INT_MAX;
- b[i] = rand() % INT_MAX;
- }
- t = clock();
- for(i = 0; i <= n; i++)
- g = __gcd(a[i], b[i]);
- cout << (clock() - t) / CLOCKS_PER_SEC << " __gcd\n";
- t = clock();
- for(i = 0; i <= n; i++)
- g = gcdZban(a[i], b[i]);
- cout << (clock() - t) / CLOCKS_PER_SEC << " gcdZban\n";
- t = clock();
- for(i = 0; i <= n; i++)
- g = gcdA(a[i], b[i]);
- cout << (clock() - t) / CLOCKS_PER_SEC << " gcdA\n";
- t = clock();
- for(i = 0; i <= n; i++)
- g = gcdT(a[i], b[i]);
- cout << (clock() - t) / CLOCKS_PER_SEC << " gcdT\n";
- t = clock();
- for(i = 0; i <= n; i++)
- g = gcd(a[i], b[i]);
- cout << (clock() - t) / CLOCKS_PER_SEC << " gcd\n";
- t = clock();
- for(i = 0; i <= n; i++)
- g = gcd1(a[i], b[i]);
- cout << (clock() - t) / CLOCKS_PER_SEC << " gcd1\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement