1435. Mutual Quality
Time Limit: 1000 MSMemorylimit: 65536 K
Total submissions: 126 (48 Users)Accepted: 30 (26 Users)
[Mysolution]
Description
Euler's function plays an important role in number theory. The value of an Euler's function of a number represents the number of positive integers that are mutually compatible with this number and not greater than this number, for example, the value of the Euler function of 6 is 2, because it is smaller than 6 and has only 1 and 5 interlace with 6. Of course, the requirement for this question is not that you need to calculate the value of a certain number of Euler's functions, but to give your positive integers A, L, and R. You need to find in the range [L, r.
Input
The input contains only one row, three positive integers A, L, and R. (1 <= L <= r <= 1,000,000,000, 2 <= A <= 1,000,000,000)
Output
The number of outputs in the range [L, R] is mutually dependent on number.
Sample Input
6 1 6
Sample output
2
Source
Doraemon @ xmu
/* Type: Euler's Function ~ I vaguely remember what yuan taught me, but I forgot the method. I wrote it according to my own understanding. It's quite simple, the key is the parity judgment... */# Include <iostream> # include <algorithm> # include <cstdio> # include <cmath> # define Manx 1025 using namespace STD; int f [Manx], P [20], num, ans; int gcd (int A, int B) {If (B = 0) return a; return gcd (B, A % B );} void fan (int n) {// evaluate the prime factor for (INT I = 2; I * I <= N; I ++) {If (N % I = 0) P [++ num] = I; while (N % I = 0) N/= I;} If (n> 1) P [++ num] = N;} void DFS (INT St, int ed, int Val, int K) {/// if (K % 2) f [ans ++] = val; // else f [ans ++] =-Val; If (ST> ed) return; For (INT I = sT; I <= Ed; I ++) //// combine to obtain the DFS factor (I + 1, Ed, P [I] * val, k + 1); // note the method} int main () {long a, L, R; while (CIN> A> L> r) {If (L = r) {// in special cases, if (gcd (A, L) = 1) printf ("1 \ n"); else printf ("0 \ n"); continue ;} num = 0; ans = 0; memset (F, 0, sizeof (f); fan (a); For (INT I = 1; I <= num; I ++) DFS (I + 1, num, P [I], 1); long sum = 0, tall = 0; // sum indicates the Euler's mass number, tall indicates the required total number of mutex (INT I = 0; I <ans; I ++) sum + = A/F [I]; // The refresh theorem. Sum = A-sum of a certain factor is obtained by combining them. If (R-l> A) tall + = (R-l) /A * sum; // periodic subtraction R % = A; l % = A; If (r = 0) r =; /// integer critical point long sum1 = 0, sum2 = 0; // sum1 indicates 1 ~ L. sum2 indicates 1 ~ R for (INT I = 0; I <ans; I ++) {sum1 + = L/f [I]; sum2 + = r/f [I];} sum1 = l-sum1; sum2 = r-sum2; tall + = sum2-sum1; If (r <= L) tall + = sum; /// obtain the completion set if (L % A & gcd (L, A) = 1) tall ++; // closed range cout <tall <Endl ;}}