比赛 20110412 评测结果 WWTTTTTTTW
题目名称 双亲数 最终得分 0
用户昵称 Citron酱 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-04-12 09:43:53
显示代码纯文本
  1. #include <fstream>
  2. #include <cmath>
  3.  
  4. #define I_F "parents.in"
  5. #define O_F "parents.out"
  6. #define MAXp 100000
  7.  
  8. using namespace std;
  9.  
  10. long a,b,d,p;
  11. long primes[MAXp];
  12. long long ans=1;
  13.  
  14. void Input();
  15. bool Prime(long);
  16. void GetPrimes();
  17. void Search(long,long,long);
  18. void Output();
  19.  
  20. int main()
  21. {
  22. Input();
  23. GetPrimes();
  24. Search(1,1,0);
  25. Output();
  26. return 0;
  27. }
  28.  
  29. void Input()
  30. {
  31. ifstream fin(I_F);
  32. fin>>a>>b>>d;
  33. fin.close();
  34. if (a>b)
  35. {
  36. int t=a;
  37. a=b;
  38. b=t;
  39. }
  40. }
  41.  
  42. bool Prime(long x)
  43. {
  44. for (long i=0, t=sqrt((double)x); (i<p)&&(primes[i]<=t); i++)
  45. if (x%primes[i]==0)
  46. return false;
  47. return true;
  48. }
  49.  
  50. void GetPrimes()
  51. {
  52. primes[0]=2,
  53. p=1;
  54. for (long i=3; i<=b/2; i+=2)
  55. if (Prime(i))
  56. primes[p++]=i;
  57.  
  58. a/=d,
  59. b/=d;
  60. }
  61.  
  62. void Search(long na, long nb, long n)
  63. {
  64. if (n<p)
  65. {
  66. long temp=na*primes[n];
  67. while (temp<=a)
  68. Search(temp,nb,n+1),
  69. temp*=primes[n];
  70. temp=nb*primes[n];
  71. while (temp<=b)
  72. Search(na,temp,n+1),
  73. temp*=primes[n];
  74. Search(na,nb,n+1);
  75. }
  76. else
  77. ans+=(na==nb)?0:1;
  78. }
  79.  
  80. void Output()
  81. {
  82. ofstream fout(O_F);
  83. fout<<ans<<'\n';
  84. fout.close();
  85. }