BZOJ_P2671 Calc(数论+莫比乌斯反演)
2016-03-22 15:04
357 查看
BZOJ传送门
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 192 Solved: 100
[Submit][Status][Discuss]
Description
给出N,统计满足下面条件的数对(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
Sol:
拆出来公因数比较好想,但是跳表不太好打还有枚举约数也不太好弄,总之……我不会
题解
另:
这句话写成
会WrongAnswer
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 192 Solved: 100
[Submit][Status][Discuss]
Description
给出N,统计满足下面条件的数对(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
Sol:
拆出来公因数比较好想,但是跳表不太好打还有枚举约数也不太好弄,总之……我不会
题解
另:
ans+=n/b/(a+b)*w;
这句话写成
ans+=w*n/b/(a+b);
会WrongAnswer
#include<cstdio> #include<cmath> #include<algorithm> #include<iostream> using namespace std; #define N 50005 //#define min(a,b) (a>b?b:a) typedef long long ll; ll top, stk ;ll ans,n; int mu ,pr ,cnt;bool b ; void GetMu(){ mu[1]=1; for(int i=2;i<N;i++){ if(!b[i]) pr[++cnt]=i,mu[i]=-1; for(int j=1;j<=cnt&&i*pr[j]<N;j++){ b[i*pr[j]]=1;if(!(i%pr[j])) break; mu[i*pr[j]]=-mu[i]; } } } void Decompose(ll x,ll i=1){ for(top=0;i*i<x;i++) if(!(x%i)) stk[++top]=i,stk[++top]=x/i; if(i*i==x) stk[++top]=i;sort(stk+1,stk+top+1); } int main(){ GetMu();scanf("%lld",&n); for(ll b=1;b*(b+1)<=n;b++){ Decompose(b); for(ll a=1,j,w=0;a<b&&b*(a+b)<=n;a=j+1,w=0){ j=min(n/(n/b/(a+b))/b-b,b-1); for(ll i=1;stk[i]<=j;i++) w+=mu[stk[i]]*(j/stk[i]-(a-1)/stk[i]); ans+=n/b/(a+b)*w; } } printf("%lld\n",ans); return 0; }
相关文章推荐
- MFC 对话框 拖动改变大小,控制位置(大小)跟随变化
- javadoc
- 关于一些基础的Java问题的解答(七)
- js中判断两个对象
- 第二界面往第一界面传值
- CSS中你可能不知道的单位
- Microsoft.Net中数字签名技术
- SQL-Serverの自動採番(IDENTITY値)の取得・リセット
- 熟悉Git使用
- rem测试用实现移动端自适应页面
- oc-10-函数与方法的区别
- dede二次开发后台自动推送链接给百度的seo插件
- [Leetcode]Binary Tree Vertical Order Traversal
- 网易云捕:一款iOS平台下方便好用的崩溃收集统计系统
- 细说算法-------最大公约数
- 采用C++的ACE库实现的一个通用的C/S架构通信程序
- oc 和 swift 互相调用
- 图解nio bytebuffer
- iOS UIDevice,UIApplicationg,UIWindows简介及其用法
- CSS选择器及CSS3新增选择器