题意:给一个矩形(非正方形)面积a和最小边长b,要求边长均大于b,求这样的矩形有几个

思路:先用到了之前学的质因数分解,还有一个新的公式:

然后我们可以先算出a的所有约数,因为只算约数个数面积重复,所以要/2;然后暴力出<b的所有约数减去。

技巧:1.用save[i]*save[i]<=temp剪枝 2.要注意判断出循环的ans是否大于1,如果大于1则表示还有一个素数没除尽,*2

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
//#include<map>
#include<string>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
const int N=1005005;
const int MOD=1000;
using namespace std;
int prime[N],save[N],pnum; //save存储了素数
void getprime(){
pnum=0;
memset(prime,0,sizeof(prime));
prime[0]=prime[1]=1;
for(long long i=2;i<N;i++){
if(!prime[i]){
save[pnum++]=i;
for(long long j=i*i;j<N;j+=i){
prime[j]=1;
}
}
}
}
int main(){
long long T,t,i,j,num;
long long a,b,ans,temp;
getprime();
scanf("%d",&T);
for(t=1;t<=T;t++){
scanf("%lld%lld",&a,&b);
if(b>a/b){
printf("Case %d: 0\n",t);
continue;
}
ans=1;temp=a;
for(i=0;i<pnum && save[i]*save[i]<=temp;i++){
if(temp%save[i]==0){
num=0;
while(temp%save[i]==0){
num++;
temp/=save[i];
}
ans*=(num+1);
}
if(temp<save[i]) break;
}
if(temp>1) ans*=2; //这里一开始没想到
ans/=2;
for(i=1;i<b;i++){
if(a%i==0) ans--;
}
printf("Case %d: %lld\n",t,ans);
}
return 0;
}

lightoj 1341 Aladdin and the Flying Carpet(算术基本定理)题解的更多相关文章

  1. [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))

    题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...

  2. LightOJ 1341 Aladdin and the Flying Carpet 算数基本定理

    题目大意:给出面积n,和最短边m,求能形成的矩形的个数(不能为正方形). 题目思路:根据算数基本定理有: 1.每个数n都能被分解为:n=p1^a1*p2^a2*^p3^a3……pn^an(p为素数); ...

  3. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  4. LightOJ - 1341 Aladdin and the Flying Carpet (算术基本定理)

    题意: 就是....求a的所有大于b的因子有多少对 算术基本定理求 所有因子 阿欧...偷张图. 注意范围 就好  ..... 解析: 在1 -1012的范围内求大于b的所有a的因子的对数(有几对) ...

  5. LightOJ 1341 - Aladdin and the Flying Carpet

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你地毯面积和最小可能边的长度,让你求有几种组合的可能. 题解:这题就厉害 ...

  6. LightOJ - 1341 Aladdin and the Flying Carpet 唯一分解定理LightOJ 1220Mysterious Bacteria

    题意: ttt 组数据,第一个给定飞毯的面积为 sss,第二个是毯子的最短的边的长度大于等于这个数,毯子是矩形但不是正方形. 思路: 求出 sss 的所有因子,因为不可能是矩形,所以可以除以 222, ...

  7. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...

  8. LightOJ 1341 - Aladdin and the Flying Carpet 基本因子分解

    http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为b,问有几种情况. 思路:对a进行素因子分解,再 ...

  9. LightOJ 1341 Aladdin and the Flying Carpet【整数分解】

    题目链接: http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341 题意: 给定一个数,将其拆分成两个数的乘 ...

随机推荐

  1. webview与js交互(转)

    原文:http://www.cnblogs.com/vanezkw/archive/2012/07/02/2572799.html 对于android初学者应该都了解webView这个组件.之前我也是 ...

  2. mysql python pymysql模块 增删改查 插入数据 介绍 commit() execute() executemany() 函数

    import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...

  3. hdu1864最大报销额(01背包)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=187#problem/G 该题要注意的就是每张单子A种类的总和不能大与600,同 ...

  4. Ubuntu16.04 安装 “宋体,微软雅黑,Consolas雅黑混合版编程字体” 等 Windows 7 下的字体

    Windows平台下,“宋体”.“微软雅黑”.“Courier New(编程字体)”用的比较多,看的也习惯了.那如何在 Ubuntu下也安装这些字体呢? 操作步骤如下: 第一步:从 Windows 7 ...

  5. 使用免费的Let's Encrypt通配符证书 升级我们的网站

    Let's Encrypt通配符证书的官方启用日期:2018年3月13日 也就是说,2018年3月13日之后,我们就可以使用Let's Encrypt通配符证书了,当然是免费的. Let's Encr ...

  6. [LeetCode] 161. One Edit Distance_Medium

    Given two strings s and t, determine if they are both one edit distance apart. Note: There are 3 pos ...

  7. isKindOfClass isMemeberOfClass 的区分

    isKindOfClass If you use such constructs in your code, you might think it is alright to modify an ob ...

  8. linux命令:帮助命令

    帮助命令:man 命令名称:man 命令英文原意:manual 命令所在路径:/usr/bin/man 执行权限:所有用户 语法:man [命令或配置文件] 功能描述:获得帮助信息 范例:$man l ...

  9. 我的2015年ccf的解答

    只做了前三个题,在本地调试好了,不知为什么错了,好歹做了那么久,就记录一下了(注:这不是标准答案,只是我给出的解答) 这是第一题的代码: #include<stdio.h> #includ ...

  10. ArrayList(JDK1.9)

    一.ArrayList概念. 1.数据结构.它是一个数组,可以动态增长的数组. 2.继承实现关系图.继承抽象List,实现List.随机方法.克隆.序列化. 3. 二.内部类. final class ...