给出n, 求有多少对(a,b) (a<b), 满足 LCM(a,b) =n
暴力求所有因数
#include <iostream> #include <algorithm> #include <vector> using namespace std; const int N =1e4+20; #define int long long const int inf =1e9 ; void sov(int n){ vector<int>v; int i,j; if(n==1){ cout<<1<<' '<<1<<endl; return ; } for(i=2;i*i<=n;i++) if(n%i==0){ v.push_back(i); if(i*i!=n) v.push_back(n/i); } v.push_back(n); v.push_back(1); int ans=0; sort(v.begin(),v.end()); for(i=0;i<v.size();i++) for(j=i;j<v.size();j++){ int x=v[i],y=v[j]; if(x/__gcd(x,y)*y==n){ ans++; } } cout << n<<' '<<ans<<endl; } signed main(){ int n;while(cin>>n&&n) sov(n); }
标签:include,const,int,10892,long,LCM,sov,Cardinality From: https://www.cnblogs.com/towboa/p/17326330.html