ÌâÄ¿´óÒ⣺ÓÐһЩ¹Ì¶¨ÈÝÁ¿µÄÆ¿×Ó£¬ÄãÏë´Ó»ðÐÇÈËÓÃk¸öÆ¿×ÓÄÇÀïÄõ½Ò»Ð©È¼ÁÏ£¬»ðÐÇÈËÖ»ÄÜ´ÓÒ»¸öÆ¿×ÓÖÐ×ªÒÆµ½ÁíÒ»¸öÆ¿×ÓÖУ¬»òÕß°ÑÒ»¸öÆ¿×ÓÖеÄȼÁϵ¹µô£¬»òÕß½«Ò»¸öÆ¿×Ó×°Âú¡£Ã¿´Î»ðÐÇÈË»á¸øÄãËûÄܸø³öµÄ×îÉÙµÄȼÁÏ¡£ÎÊÄãÄܹ»µÃµ½µÄ×î¶àµÄȼÁÏ¡£
˼·£ºyyһϷ¢ÏÖһЩƿ×ÓÖÐÄܸø³öµÄ×îÉÙµÄȼÁϾÍÊÇÕâЩƿ×ÓÈÝÁ¿µÄgcd£¬ÓÚÊǾͰÑËùÓÐµÄÆ¿×ÓÈÝÁ¿µÄÔ¼ÊýŪ³öÀ´£¬ÕÒµ½×î´óµÄ´óÓÚk¸öµÄ¾ÍÊǴ𰸡£
CODE£º
#include#include #include #include #define MAX 10000010 using namespace std; int cnt,k; int arr[MAX],total; inline void Work(int x) { for(int i = 1;; ++i) { if(i * i >= x) { arr[++total] = i; return ; } if(x % i == 0) arr[++total] = i,arr[++total] = x / i; } } int main() { cin >> cnt >> k; for(int x,i = 1; i <= cnt; ++i) { scanf("%d",&x); Work(x); } sort(arr + 1,arr + total + 1); int temp = 1; for(int i = total - 1; i; --i) { if(arr[i] == arr[i + 1]) ++temp; else { if(temp >= k) { cout << arr[i + 1] << endl; return 0; } temp = 1; } } return 0; }