Hdu4135 -- Co-prime (Euler's Function + refresh principle)
Co-prime
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64uSubmit StatusAppoint description: System Crawler)
Description
Given a number N, you are asked to count the number of integers between A and B random sive which are relatively prime to N.
Two integers are said to be co-prime or relatively prime if they have no common positive divisors other than 1 or, equivalently, if their greatest common divisor is 1. the number 1 is relatively prime to every integer.
Input
The first line on input contains T (0 <T <= 100) the number of test cases, each of the next T lines contains three integers A, B, N where (1 <= A <= B <= 10 15) and (1 <= N <= 10 9 ).
Output
For each test case, print the number of integers between A and B random sive which are relatively prime to N. Follow the output format below.
Sample Input
21 10 23 15 5
Sample Output
Case #1: 5Case #2: 10
Hint
In the first test case, the five integers in range [1,10] which are relatively prime to 2 are {1,3,5,7,9}.
Calculate the number of mutual quality between a and B.
Calculate the number of interconnectivity with n in 1 to A-1 and in 1 to B, and calculate the number of interconnectivity with n in 1 to m, respectively, first, calculate the number of numbers between 1 to m and n that are not in mutual quality.
Calculate the number of prime numbers after n decomposition, and use the binary number to represent the selection and deselection of the I-th prime number. then obtain the number contained in m. If an odd number of prime numbers is selected, the statistical results are accumulated, if it is an even number, subtract.
#include
#include
#include using namespace std ;#define LL __int64int prim[1000000] , vis[1000000] , cnt ;void sieve(){ memset(vis,0,sizeof(vis)) ; cnt = 0 ; LL i , j ; for(i = 2 ; i <= 1000000 ; i++) { if( !vis[i] ) { prim[cnt++] = i ; for(j = i*i ; j < 1000000 ; j += i) vis[j] = 1 ; } }}LL p[1000] , p_num ;LL f(LL n,LL m){ LL k = n , temp , ans = 0 ; int i , j , num ; for(i = 0 , p_num = 0 ; i < cnt ; i++) { if( k % prim[i] == 0 ) { p[p_num++] = prim[i] ; } while( k % prim[i] == 0 ) { k /= prim[i] ; } if(k == 1) break ; } if( k > 1 ) p[p_num++] = k ; for(i = 1 ; i < (1<