51nod 1060反素数
经典题。
#include<map> #include<queue> #include<stack> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define INF 1000000001 #define ll unsigned long long #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; const int MAXN = 510; int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,39,41,43,47,53,59,61,67}; ll n; ll ans,ans_cnt; void getarcprime(ll cur,ll cnt,int limit,int k) { if(cur > n)return; if(cnt > ans_cnt){ ans_cnt = cnt; ans = cur; } else if(cnt == ans_cnt && cur < ans){ ans = cur; } for(int i = 1; i <= limit; i++){ if(n / prime[k] < cur){ return; } getarcprime(cur*prime[k],cnt*(i+1),i,k+1); cur = cur*prime[k]; } } int main() { int t; cin >>t; while(t--){ cin >>n; ans = 0; ans_cnt = 0; getarcprime(1,1,60,0); cout<<ans<<" "<<ans_cnt<<endl; } return 0; }