找回密码
 欢迎注册
查看: 15946|回复: 15

[讨论] 寻找最小素数P,满足如下条件

[复制链接]
发表于 2008-6-26 16:03:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
对所有小于100的素数$p_i$
使得$P -= (p_i - 1)   mod p_i$
即$P -= 1 (mod 2), \quad p-=2 (mod 3), \quad p-= 4 (mod 5) ...  p-= 96 (mod 97)$
要求程序行越少越好,运行时间不得超过1分钟
只能使用标准库

哈哈

[ 本帖最后由 无心人 于 2008-6-26 16:35 编辑 ]
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-6-26 16:34:23 | 显示全部楼层
$p_1$是什么?2?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-6-26 16:36:40 | 显示全部楼层
这个不就是
$P=\prod_{p_i<100} p_i -1$
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2008-6-26 16:39:05 | 显示全部楼层
素数阿

老大
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-6-26 16:41:50 | 显示全部楼层
哦,那你得加条件P也是素数,也得先将我上面那个乘积计算出来,然后找最小的$lambda$,使得$lambda \prod_{p_i<100}p_i-1$是素数
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-6-26 16:42:53 | 显示全部楼层
不过只允许使用标准库做起来比较麻烦
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2008-6-26 16:43:00 | 显示全部楼层


呵呵,公式都出来了阿

[ 本帖最后由 无心人 于 2008-6-26 17:18 编辑 ]
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-6-26 17:08:01 | 显示全部楼层
Call HugeCalc V8.0.0.0
0.000878 s      λ = 4
P=9222271855782073699012408589327024279
请按任意键继续. . .

代码如下:
  1. // HugeCalcDemo.cpp : Defines the entry point for the console application.
  2. //

  3. //        Project -> Setting -> C/C++ -> Code Generation --> Use run-time library:
  4. //                Win32 Debug:        Debug Multithreaded DLL
  5. //                Win32 Release:        Multithreaded DLL

  6. #include <stdio.h>

  7. #include "../../../HugeCalc_API/CppAPI/Include/HugeCalc.h"        // 公共接口
  8. #include "../../../HugeCalc_API/CppAPI/Include/HugeInt.h"        // 10进制系统
  9. #include "../../../HugeCalc_API/CppAPI/Include/HugeIntX.h"        // 16进制系统

  10. #pragma message( "automatic link to ../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
  11. #pragma comment( lib, "../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )

  12. #if 1
  13.         #define _Test_HI
  14.         #define integer CHugeInt
  15. #else
  16.         #define _Test_HX
  17.         #define integer CHugeIntX
  18. #endif

  19. int main(int argc, char* argv[])
  20. {
  21. //        printf("Hello World!\n");

  22.         printf( "Call %s\r\n", HugeCalc::GetVer());

  23.         if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel())
  24.         {
  25.                 printf( "\r\n警告:您未通过 HugeCalc.dll 的许可认证!\r\n" \
  26.                         "\r\n解决方案可选下列方案之一:" \
  27.                         "\r\n    一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
  28.                         "\r\n    二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。\r\n\r\n" );

  29.                 system( "pause" );
  30.                 return (-1);
  31.         }

  32.         // 初始化
  33.         HugeCalc::EnableTimer( TRUE );
  34.         HugeCalc::ResetTimer();

  35.         #define _COUNT__PRIME_LESS100        25

  36.         UINT32 pList[_COUNT__PRIME_LESS100];
  37.         HugeCalc::GetPrimeList( pList, _COUNT__PRIME_LESS100, 1, 100 );

  38.         integer hugeProduct;
  39.         hugeProduct.Product( CVECTOR_UINT32( pList, _COUNT__PRIME_LESS100 ) );

  40.         UINT32 u32Count = 0;

  41.         integer hugeResult( -1 );
  42.         do
  43.         {
  44.                 ++u32Count;
  45.                 hugeResult += hugeProduct;
  46.         } while( !hugeResult.IsPrime() );

  47.         // 暂停计时
  48.         HugeCalc::EnableTimer( FALSE );

  49.         // 输出
  50.         printf( "%s\tλ = %u\r\nP=%s\r\n", HugeCalc::GetTimerStr(), u32Count, (LPCTSTR)hugeResult );

  51.         system( "pause" );

  52.         return 0;
  53. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2008-6-26 17:18:00 | 显示全部楼层


因为太容易所以要求不用大数库哦
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-6-26 19:05:27 | 显示全部楼层
在发8#时要下班了,所以比较匆忙,
该程序还可更精简的,比如 hugeProduct 仅用一条语句即可求得:hugeProduct.Primorial( 100 );

下面的程序可以分别求与在10内、100内、1000内、。。。的所有素数的同余数为(-1)的最小素数:
  1. // HugeCalcDemo.cpp : Defines the entry point for the console application.
  2. //

  3. //    Project -> Setting -> C/C++ -> Code Generation --> Use run-time library:
  4. //        Win32 Debug:    Debug Multithreaded DLL
  5. //        Win32 Release:    Multithreaded DLL

  6. #include < stdio.h >

  7. #include "../../../HugeCalc_API/CppAPI/Include/HugeCalc.h"  // 公共接口
  8. #include "../../../HugeCalc_API/CppAPI/Include/HugeInt.h"   // 10进制系统
  9. #include "../../../HugeCalc_API/CppAPI/Include/HugeIntX.h"  // 16进制系统

  10. #pragma message( "automatic link to ../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
  11. #pragma comment( lib, "../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )

  12. int main(int argc, char* argv[])
  13. {
  14. //  printf("Hello World!\n");
  15.     CHugeIntX hugeAdd, hugeResult;
  16.     UINT32 n, k;

  17.     printf( "Call %s\r\n", HugeCalc::GetVer());

  18.     if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel())
  19.     {
  20.         printf( "\r\n警告:您未通过 HugeCalc.dll 的许可认证!\r\n" \
  21.             "\r\n解决方案可选下列方案之一:" \
  22.             "\r\n    一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
  23.             "\r\n    二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。\r\n\r\n" );

  24.         system( "pause" );
  25.         return (-1);
  26.     }

  27.     for ( n=10; n<=1000000; n*=10 )
  28.     {
  29.         // 初始化
  30.         HugeCalc::EnableTimer( TRUE );
  31.         HugeCalc::ResetTimer();

  32.         hugeAdd.Primorial( n );
  33.         hugeResult = -1;

  34.         k = 0;
  35.         do
  36.         {
  37.             ++k;
  38.             hugeResult += hugeAdd;
  39.         } while( !hugeResult.IsPrime() );

  40.         // 暂停计时
  41.         HugeCalc::EnableTimer( FALSE );

  42.         // 输出
  43.         printf( "%s\tP = %u*%u# - 1 = %s\r\n", HugeCalc::GetTimerStr( FT_HHMMSS_ms ), k, n,
  44.             hugeResult.GetStrRadix( 10, NULL, FS_NORMAL ));
  45.     }

  46.     system( "pause" );

  47.     return 0;
  48. }
复制代码
不过,本题若限定仅用标准库就麻烦了,难点全在大数的素性判定上(当然大数的四则运算也是基本)。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-5-3 08:08 , Processed in 0.049166 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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