题意:给定n,求x,y,z三个整数,使得x|n,y|n,z|n,且xyz最小
n<=1e6
思路:
不定方程1/x+1/y+1/z=1
只有(2,3,6)(2,4,4) (3,3,3)三组正整数解
设x<=y<=z,x=2或3
x=2时1/y+1/z=1/2,y=3或4时存在z
x=3时1/y+1/z=2/3,y=3时存在z
只有这三种情况
1 #include<cstdio> 2 #include<cstdlib> 3 #include<algorithm> 4 #include<iostream> 5 #include<cstring> 6 using namespace std; 7 int cas; 8 long long ans,n; 9 10 int main() 11 { 12 // freopen("1001.in","r",stdin); 13 // freopen("1001.out","w",stdout); 14 scanf("%d",&cas); 15 for(int i=1;i<=cas;i++) 16 { 17 scanf("%lld",&n); 18 ans=-1; 19 if(!(n%6)) ans=n/2*n/3*n/6; 20 if(!(n%4)) ans=n/2*n/4*n/4; 21 if(!(n%3)) ans=n/3*n/3*n/3; 22 printf("%lld ",ans); 23 } 24 return 0; 25 }