LightOJ 1341 Aladdin and the Flying Carpet
来源:互联网 发布:淘宝联盟高佣手机入口 编辑:程序博客网 时间:2024/05/02 02:05
题意:
a可以写成两个因子相乘的形式,要找出一共有多少中两个不同因子相乘的组合,要求每个因子都大于b
思路:
求两个因子的组合只要求出所有因子数然后除以二就行了,求因子数为:
sum=(s[0]+1)*(s[1]+1)*(s[2]+1)……//s[i]为a的一个素因子的个数。
然后暴力求出小于b的所有因子减去就行了,因为当b>sqrt(a)时所有因子都不满足,所以最大只要扫到1e6的大小刚好卡过。
代码:
#define N 1123456long long n,m;long long flag,sum,ave,ans,res,len,ans1,ans2;bool mark[N];int pri[N],cnt;void SP(){ cnt=0; memset(mark,true,sizeof(mark)); mark[0]=mark[1]=false; for(int i=2;i<N;i++) { if(mark[i]) pri[cnt++]=i; for (int j=0;(j<cnt)&&(i*pri[j]<N);j++) { mark[i*pri[j]]=false; if (i%pri[j]==0) break; } }}int main(){ long long i,j,k,kk,t,x,y,z; SP(); scanf("%lld",&k); kk=0; while(k--) { scanf("%lld%lld",&n,&m); sum=0; if(m<sqrt(n)&&n) { sum=1;t=n; for(i=0;i<cnt&&pri[i]<=t;i++) { res=0; while(t%pri[i]==0&&t)t/=pri[i],res++; sum*=(res+1); } if(t>1) sum*=2; sum=sum/2; for(i=1;i<m;i++) if(n%i==0) sum--; } printf("Case %lld: %lld\n",++kk,sum); } return 0;}
0 0
- lightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1341Aladdin and the Flying Carpet
- LightOJ 1341 - Aladdin and the Flying Carpet
- LightOJ 1341 Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- Aladdin and the Flying Carpet LightOJ
- LightOJ-1314 Aladdin and the Flying Carpet
- LightOJ 1341 - Aladdin and the Flying Carpet【合数分解】
- lightoj 1341 Aladdin and the Flying Carpet (唯一分解定理)
- LightOJ 1341 Aladdin and the Flying Carpet(算术基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- lightOj 1341Aladdin and the Flying Carpet 算数基本定理
- Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet
- 数组名与指针
- 异常处理:使用UTF-8编码Mysql仍然抛出Incorrect string value异常
- Java文件读写
- 2015找工作心得体会
- plsql 去除logon选择框
- LightOJ 1341 Aladdin and the Flying Carpet
- c 代码定义的位置与初始化关系
- [从零开始学libGDX]第二章:libgdx环境的搭建-Mac篇
- Ajax
- 使用Intent进行数据的传输(可以是两个App间)
- 《赢在中国蓝天碧水间》观后感
- Apache cxf JaxWs基本应用 (如何在Spring中配置CXF,测试的时候与一般services不一样)
- Android 布局优化
- Schei� encoding: Java, MySQL and multi-byte UTF-8 support