Description
As we all know, I am a good man!
So not too difficult problem, test instructions very simple to give you two number N and M, ask you how many pairs of positive integers to greatest common divisor is n, least common multiple is M
Finally the friendship provides the problem solving code (I am very good)
void Solve ()
{
Long long n, m;
scanf ("%lld%lld", &n, &m);
int ans = 0;
For (long long i = 1; I <= m; i++)
{
for (long long j = i; j <= m; j++) { if (gcd(i, j) == n && lcm(i, j) == m) ans++; }
}
printf ("%d\n", ans);
}
I wish you a pleasant AC! The best AK, send a certain Yang promise ^_^
Input
Input line 1th is an integer t representing the total T-group data. Next is the T Group data, each group of data accounted for 1 rows, each line has 2 integers n,m (1 <= N, M <= 10000000000), two numbers separated by a space.
Output
The result outputs a T-line corresponding to the T-group data. (t<=100)
How many pairs of positive integer pairs are output for each line (see how nice I am that you don't have to output all the integer pairs)
Sample Input
3
1 1
7 10086
4 16
Sample Output
1
0
1
Solution:
A very important conversion: Ask (x, y) = k, 1 <= x, y <= n logarithm equals (x, y) = 1, 1 <= x, y <= n/k logarithm
#include <stdio.h>#include <iostream>#include <math.h>#include <stdlib.h>#include <ctype.h>#include <algorithm>#include <vector>#include <string.h>#include <queue>#include <stack>#include <set>#include <sstream>#include <time.h>#include <utility>#include <malloc.h>#include <stdexcept>#include <iomanip>#include <iterator>using namespace STD;Long LonggcdLong LongALong Longb) {if(b = =0)returnAElse returnGCD (b,a%b);}voidSolveLong LongN) {intAns =0; for(Long Longi =1; I <=sqrt(n1.0); i++) {if(n%i = =0) {Long Longj = n/i;if(GCD (i, j) = =1) ans++; } }printf("%d\n", ans);}intMain () {intTLong LongN, M;scanf("%d", &t); while(t--) {scanf("%lld%lld", &n,&m);if(m% n! =0) {printf("0\n");Continue; }Long LongTMP = m/n; Solve (TMP); }return 0;}
I'm a good guy.