int main(){
    int cases;
    scanf("%d",&cases);
    while(cases){
        long long a,b;
        scanf("%llu %llu", &a, &b);
        printf("%llu\n",gcd2(a,b) );
        --cases;
    }
    // clock_t start,end ;
    // unsigned long long a,b;
    // a = 400000;
    // b = 1000000000000000000;
    // start = clock();
    // printf("GCD of 4 and 180 is %llu \n", gcd(a,b));

    // end = clock();
    // double t = (double)(end-start)/CLOCKS_PER_SEC;
    // printf("Elapsed: %f\n",t );
    //  start = clock();
    // printf("GCD of 4 and 180 is %llu \n", gcd2(a,b));

    // end = clock();
    //  t = (double)(end-start)/CLOCKS_PER_SEC;
    // printf("Elapsed: %f\n",t );
    return 0;
}
Example #2
0
File: gcd-gmp.c Project: ip1981/GCD
void gcdn(mpz_t r, mpz_t a[], size_t n)
{
    size_t i;
    mpz_set(r, a[0]);
    for (i = 1; i < n; i++)
        gcd2(r, r, a[i]); /* mpz_gcd ;-) */
}
int main () {
    printf("iterative sum of squares from 1 to 10: %d\n",
            summation(square, 1, 10));
    printf("recursive gcd of 24 and 40: %d\n", gcd(24, 40));
    printf("recursive sum of squares from 1 to 10: %d\n",
            summation2(square, 1, 10));
    printf("iterative gcd of 24 and 40: %d\n", gcd2(24, 40));
    printf("tail-recursive gcd of 24 and 40: %d\n", gcd3(24, 40));
}
Example #4
0
int main(void){
	char word1[100] = "racecar ten";
	char word2[100] = "Go hang a salami, I'm a lasagna hog";
	char word3[100] = "Banana tub";
	int j = 0, pal = -1;

	pal = isPalindrome(word1, 0, strlen(word1));

	//printf("Palindrome = %d\n", pal);

	//printBinaryNum("xxxxxxxx");

	j = gcd2(132, 20);
	printf("Greatest common denominator = %d\n", j);

}
Example #5
0
void ch1()
{
	// 循环语句的辗除法,求两个整数的最大公约数
	printf("319,377最大公约数:%d\n",gcd1(319,377)); //29

	// 循环语句的辗除法,求两个整数的最大公约数
	printf("319,377最大公约数:%d\n",gcd2(319,377)); //29

	// 递归调用的辗除法,求两个整数的最大公约数
	printf("377,319最大公约数:%d\n",gcd3(377,319)); //29
	printf("319,377最大公约数:%d\n",gcd3(319,377)); //29
	printf("377,319最大公约数:%d\n",gcd4(377,319)); //29
	printf("319,377最大公约数:%d\n",gcd4(319,377)); //29
	printf("377,319最大公约数:%d\n",gcd5(377,319)); //29
	printf("319,377最大公约数:%d\n",gcd5(319,377)); //29

	// 最小公倍数=两整数的乘积÷最大公约数
	//printf("319,377最小公倍数:%d\n",multiple (319,377));  
}
Example #6
0
void gcd_main2(){
	int a, b;
	a = 128;
	b = 72;
	printf("%dと%dの最大公約数は%d\n", a, b, gcd2(a, b));
}
Example #7
0
GF2m gcd(const GF2m& b1,const GF2m& b2)
{
    GF2m g;
    gcd2(b1.fn,b2.fn,g.fn);
    return g;
}
Example #8
0
int gcd2(int a, int b) {
	if(b == 0) return a;
	else return gcd2(b, a % b);
}