比赛 |
20110412 |
评测结果 |
WWTTTTTTTW |
题目名称 |
双亲数 |
最终得分 |
0 |
用户昵称 |
Citron酱 |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2011-04-12 09:43:53 |
显示代码纯文本
- #include <fstream>
- #include <cmath>
-
- #define I_F "parents.in"
- #define O_F "parents.out"
- #define MAXp 100000
-
- using namespace std;
-
- long a,b,d,p;
- long primes[MAXp];
- long long ans=1;
-
- void Input();
- bool Prime(long);
- void GetPrimes();
- void Search(long,long,long);
- void Output();
-
- int main()
- {
- Input();
- GetPrimes();
- Search(1,1,0);
- Output();
- return 0;
- }
-
- void Input()
- {
- ifstream fin(I_F);
- fin>>a>>b>>d;
- fin.close();
-
- if (a>b)
- {
- int t=a;
- a=b;
- b=t;
- }
- }
-
- bool Prime(long x)
- {
- for (long i=0, t=sqrt((double)x); (i<p)&&(primes[i]<=t); i++)
- if (x%primes[i]==0)
- return false;
- return true;
- }
-
- void GetPrimes()
- {
- primes[0]=2,
- p=1;
- for (long i=3; i<=b/2; i+=2)
- if (Prime(i))
- primes[p++]=i;
-
- a/=d,
- b/=d;
- }
-
- void Search(long na, long nb, long n)
- {
- if (n<p)
- {
- long temp=na*primes[n];
- while (temp<=a)
- Search(temp,nb,n+1),
- temp*=primes[n];
- temp=nb*primes[n];
- while (temp<=b)
- Search(na,temp,n+1),
- temp*=primes[n];
- Search(na,nb,n+1);
- }
- else
- ans+=(na==nb)?0:1;
- }
-
- void Output()
- {
- ofstream fout(O_F);
- fout<<ans<<'\n';
- fout.close();
- }