fork download
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. long long w,l,k;
  6.  
  7. long long pri(long long n) {
  8. long long cnt=0;
  9. for (int i=2;i*i<=n;i++) {
  10.  
  11. while (n%i==0) {
  12. n/=i;
  13. cnt++;
  14. }
  15.  
  16. }
  17. if (n>1)cnt++;
  18. return cnt;
  19. }
  20.  
  21. void div(long long x,set<long long >&arr) {
  22.  
  23. for (int i=1;i*i<=x;i++) {
  24. if (x%i==0) {
  25. if (i*i!=x) {
  26.  
  27. arr.insert(i);
  28. arr.insert(x/i);
  29. }else {
  30. arr.insert(i) ;
  31. }
  32. }
  33. }
  34.  
  35.  
  36.  
  37.  
  38. }
  39.  
  40.  
  41.  
  42. int main() {
  43. //freopen("","r",stdin);
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46.  
  47. cin>>w>>l>>k;
  48.  
  49. set<long long>one,two;
  50. set<long long,greater<>>three;
  51. div(l,one);
  52. div(w,two);
  53.  
  54.  
  55. for (auto &i:one) {
  56. if (two.count(i)) {
  57. three.insert(i);
  58.  
  59. }
  60. }
  61.  
  62. long long ans=-1;
  63. for (auto &i:three) {
  64. // cout<<pri(i)<<endl;
  65. if (pri(i)==k) {
  66. ans=(l)/(i);
  67. ans*=w;
  68. ans/=i;
  69. break;
  70. }
  71. }
  72.  
  73. cout<<ans<<endl;
  74.  
  75.  
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
Success #stdin #stdout 0s 5320KB
stdin
12 12 3
stdout
1