POJ 3641 Pseudoprime numbers 题解 《挑战程序设计竞赛》 � 码农场
伪素数:满足①p不是素数②存在a > 1使得ap = a (mod p)的p是伪素数,给出p和a,判断p是否是伪素数。
Read full article from POJ 3641 Pseudoprime numbers 题解 《挑战程序设计竞赛》 � 码农场
POJ 3641 Pseudoprime numbers 题解 《挑战程序设计竞赛》 � 码农场
伪素数:满足①p不是素数②存在a > 1使得ap = a (mod p)的p是伪素数,给出p和a,判断p是否是伪素数。
Read full article from POJ 3641 Pseudoprime numbers 题解 《挑战程序设计竞赛》 � 码农场
Basic and Extended Euclidean algorithms - GeeksforGeeks
Extended Euclidean Algorithm:
Extended Euclidean algorithm also finds integer coefficients x and y such that:
ax + by = gcd(a, b)
Read full article from Basic and Extended Euclidean algorithms - GeeksforGeeks
void radixSortDates(Date arr[], int n){ // First sort by day countSortDay(arr, n); // Then by month countSortMonth(arr, n); // Finally by year countSortYear(arr, n);}// A function to do counting sort of arr[] according to// dayvoid countSortDay(Date arr[], int n){ Date output[n]; // output array int i, count[31] = {0}; // Store count of occurrences in count[] for (i=0; i<n; i++) count[arr[i].d - 1]++; // Change count[i] so that count[i] now contains // actual position of this day in output[] for (i=1; i<31; i++) count[i] += count[i-1]; // Build the output array for (i=n-1; i>=0; i--) { output[count[arr[i].d - 1] - 1] = arr[i]; count[arr[i].d - 1]--; } // Copy the output array to arr[], so that arr[] now // contains sorted numbers according to curent digit for (i=0; i<n; i++) arr[i] = output[i];}// A function to do counting sort of arr[] according to// month.void countSortMonth(Date arr[], int n){ Date output[n]; // output array int i, count[12] = {0}; for (i = 0; i < n; i++) count[arr[i].m - 1]++; for (i = 1; i < 12; i++) count[i] += count[i - 1]; for (i=n-1; i>=0; i--) { output[count[arr[i].m - 1] - 1] = arr[i]; count[arr[i].m - 1]--; } for (i = 0; i < n; i++) arr[i] = output[i];}// A function to do counting sort of arr[] according to// year.void countSortYear(Date arr[], int n){ Date output[n]; // output array int i, count[1000] = {0}; for (i = 0; i < n; i++) count[arr[i].y - 2000]++; for (i = 1; i < 1000; i++) count[i] += count[i - 1]; for (i = n - 1; i >= 0; i--) { output[count[arr[i].y - 2000] - 1] = arr[i]; count[arr[i].y - 2000]--; } for (i = 0; i < n; i++) arr[i] = output[i];}