Calc
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 451 Solved: 234
[Submit][Status][Discuss]
Description
给出N,统计满足下面条件的数对(a,b)的个数:
1.1<=a<b<=N
2.a+b整除a*b
1.1<=a<b<=N
2.a+b整除a*b
Input
一行一个数N
Output
一行一个数表示答案
Sample Input
15
Sample Output
4
HINT
数据规模和约定
Test N Test N
1 <=10 11 <=5*10^7
2 <=50 12 <=10^8
3 <=10^3 13 <=2*10^8
4 <=5*10^3 14 <=3*10^8
5 <=2*10^4 15 <=5*10^8
6 <=2*10^5 16 <=10^9
7 <=2*10^6 17 <=10^9
8 <=10^7 18 <=2^31-1
9 <=2*10^7 19 <=2^31-1
10 <=3*10^7 20 <=2^31-1
Source
http://blog.csdn.net/popoqqq/article/details/45095601
1 #pragma GCC optimize(2) 2 #pragma G++ optimize(2) 3 #include<cstdio> 4 #include<iostream> 5 #include<cstring> 6 #include<cmath> 7 #define ll long long 8 #define mod 1000000007 9 #define N 50005 10 using namespace std; 11 inline int read() 12 { 13 int x=0,f=1;char ch=getchar(); 14 while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} 15 while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 16 return x*f; 17 } 18 19 bool flag[N]; 20 int tot,p[N],miu[N],n,m,pos; 21 ll ans; 22 23 void pre() 24 { 25 miu[1]=1; 26 for (int i=2;i<N;i++) 27 { 28 if (!flag[i]) p[++tot]=i,miu[i]=-1; 29 for (int j=1;j<=tot&&p[j]*i<N;j++) 30 { 31 flag[i*p[j]]=1; 32 if (i%p[j]==0) break; 33 miu[i*p[j]]=-miu[i]; 34 } 35 } 36 } 37 int main() 38 { 39 pre(); 40 scanf("%d",&n);m=sqrt(n); 41 for (int d=1;d<=m;d++) 42 { 43 for (int i=2;i<=m/d;i++) 44 { 45 int last=n/(d*d*i); 46 for (int x=i+1,p=0;x<=2*i-1&&x<=last;x=pos+1) 47 { 48 pos=last/(last/x); 49 ans+=1LL*miu[d]*(min(pos,2*i-1)-x+1)*(last/x); 50 } 51 } 52 } 53 printf("%lld",ans); 54 }