鱼C论坛

 找回密码
 立即注册
查看: 3066|回复: 6

题目108:求解丢番图方程1/x + 1/y = 1/n

[复制链接]
发表于 2016-8-19 17:13:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 欧拉计划 于 2016-8-21 00:41 编辑
Diophantine reciprocals I

In the following equation x, y, and n are positive integers.

QQ20160819-1@2x.png


For n = 4 there are exactly three distinct solutions:

QQ20160819-2@2x.png

What is the least value of n for which the number of distinct solutions exceeds one-thousand?

NOTE: This problem is an easier version of Problem 110; it is strongly advised that you solve this one first.


题目:

在如下方程中,x,y 和 n 皆为正整数。

QQ20160819-1@2x.png


对于 n=4,一共有三个不同的解:

QQ20160819-2@2x.png

要使方程拥有超过一千个不同的解,最小的 n 是多少?

注意:该题目是题目 110 的一个简单版,强烈建议你先做这一个题目。


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-10-23 15:04:53 | 显示全部楼层
这题还是要找规律,通过观察前几个n(n>60),可以发现,基本上每个不同解的个数+1,n都是60的倍数。
  1. n = 60
  2. while True:
  3.         count = 0
  4.         for x in range(n+1,2*n+1):
  5.                 if x*n % (x-n) == 0:
  6.                         count += 1
  7.         if count > 1000:
  8.                 break
  9.         n += 60
  10. print (n, count)
复制代码

答案180180
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-4-26 10:50:25 | 显示全部楼层
这个方程可以通过代换x=n+x1,y=n+y1。得到x1*y1=n^2。所以方程的解的个数等于n^2的因数分解的个数。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-7-24 17:35:44 | 显示全部楼层
guosl 发表于 2019-4-26 10:50
这个方程可以通过代换x=n+x1,y=n+y1。得到x1*y1=n^2。所以方程的解的个数等于n^2的因数分解的个数。

好像并不对哦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-7 10:37:37 | 显示全部楼层

这个方程可以通过代换x=n+x1,y=n+y1。得到x1*y1=n^2。所以方程的解的个数等于n^2的因数分解中小于等于n的因数个数。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 0 反对 1

使用道具 举报

发表于 2020-4-9 20:07:16 | 显示全部楼层
本帖最后由 代号-K 于 2020-4-9 20:12 编辑

110 的 answer is : 1260
由于 n 的 可拆解 为  n^2 中 两个因数的乘积
所以可以编写代码如下:
  1. void getDiophantineReciprocals(int flag){
  2.     int num = 1;
  3.     int count;
  4.     int i;
  5.     ElementType numPow;
  6.     while(true){
  7.         count = 1;
  8.         i = 2;
  9.         num++;
  10.         numPow = (ElementType) pow(num, 2);
  11.         while(i <= num){
  12.             if(numPow % i == 0){
  13.                 count++;
  14.             }
  15.             i++;
  16.         }
  17.         if(count >= flag){
  18.             printf("get it\n");
  19.             printf("%d has %d\n", num,count);
  20.             return;
  21.         }
  22.         printf("%d has %d\n",num,count);
  23.     }
  24. }

  25. int main(int argc, char *argv[]){
  26.     getDiophantineReciprocals(110);
  27.     return 0;
  28. }
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-1-31 11:11:47 | 显示全部楼层
  1. /*
  2. 答案:180180
  3. 耗时:0.0027585秒
  4. */
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <omp.h>
  8. using namespace std;

  9. const int N = 1000000;
  10. const int M = 1000;
  11. const int nSteps = 100;
  12. int p[N];//p[i]为i的一个素因数,用于i的素因数分解

  13. int main(void)
  14. {
  15.   int nK = 5;
  16.   volatile bool bContinue = true;
  17.   int nMinK = 0x7fffffff;
  18.   double t = omp_get_wtime();
  19. #pragma omp parallel shared(nK,bContinue) reduction(min:nMinK)
  20.   {
  21.     //应用筛法求每个数的一个素因数
  22. #pragma omp for
  23.     for (int i = 1; i < N; ++i)
  24.       p[i] = i;
  25. #pragma omp single
  26.     for (int i = 2; i <= M; ++i)
  27.     {
  28.       if (p[i] < i)
  29.         continue;
  30.       for (int j = i * i; j < N; j += i)
  31.         p[j] = i;
  32.     }
  33.     while (bContinue)
  34.     {
  35.       int k = 0;
  36. #pragma omp critical(c1)
  37.       {
  38.         k = nK;
  39.         nK += nSteps;
  40.       }
  41.       for (int i = k; i < k + nSteps; ++i)
  42.       {
  43.         //对i^2求其因数的分解
  44.         int nCount = 1;//记录i的因数个数
  45.         int x = i;
  46.         while (x > 1)
  47.         {
  48.           int y = 0, z = p[x];
  49.           while ((x % z) == 0)
  50.           {
  51.             ++y;
  52.             x /= z;
  53.           }
  54.           nCount *= (2 * y + 1);
  55.         }
  56.         if (nCount > 2000)//此时至少有1000个因数小于i
  57.         {
  58.           nMinK = min(nMinK, i);
  59. #pragma omp critical(c2)
  60.           bContinue = false;
  61.           break;
  62.         }
  63.       }
  64.     }
  65.   }
  66.   t = omp_get_wtime() - t;
  67.   cout << nMinK << endl << t << endl;
  68.   return 0;
  69. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-21 14:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表