题目大意:给出面积n,和最短边m,求能形成的矩形的个数(不能为正方形)。

题目思路:根据算数基本定理有:

1.每个数n都能被分解为:n=p1^a1*p2^a2*^p3^a3……pn^an(p为素数);

2.n的正因数的个数sum为:sum=(1+a1)*(1+a2)*(1+a3)……(1+an);

最短边为m,若m>=sqrt(n),则无解。所以m最多我10^6,可遍历找出1-m中n的因子,并用sum去减去这类因子的个数。

ps:最近一直想去证明算数基本定理,可是感觉能力不够,唉,慢慢来吧。

#include<cstdio>
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 1000005
#define mod 1000000007 using namespace std; long long p[MAX],v[MAX],num_prime; void GetPriem()//获得素数
{
memset(p,,sizeof(p));
memset(v,,sizeof(v));
for(int i=;i<MAX;i++)
{
if(!v[i])
{
p[++num_prime]=i;
for(int j=i;j<MAX;j+=i)
v[j]=;
}
}
} long long Ans(long long n)
{
long long cnt,sum=;
for(int i=;i<=num_prime && p[i]<=n;i++)
{
if(n%p[i]==)
{
cnt=;
while(n%p[i]==)
{
cnt++;
n/=p[i];
}
sum*=(cnt+);
}
}
if(n > )
sum*=;
return sum;
} int main()
{
GetPriem();
int T,cnt=,i,j;
long long n,m;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
if(n/m < m)
{
printf("Case %d: %lld\n",cnt++,);
continue;
}
long long ans=Ans(n)/;
for(i=;i<m;i++)
{
if(n%i==)
ans--;
}
printf("Case %d: %lld\n",cnt++,ans);
}
return ;
}

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 (唯一分解定理 + 素数筛选)

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

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

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

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

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

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

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

  6. LightOJ 1341 - Aladdin and the Flying Carpet

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

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

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

  8. LightOJ 1341 Aladdin and the Flying Carpet 数学

    题意:给个矩形的面积a,和矩形的最小边长b,问有多少种矩形的方案(不能是正方形) 分析:a可以写成x,y,因为不能是正方形,所以设x<y,那么x<sqrt(a),y>sqrt(a) ...

  9. LightOJ 1341 Aladdin and the Flying Carpet(整数拆分定理)

    分析:题目并不难理解,就是一些细节上的优化需要我们注意,我在没有优化前跑了2000多MS,优化了一些细节后就是400多MS了,之前还TLE了好几次. 方法:将整数拆分为质因子以后,表达为这样的形式,e ...

随机推荐

  1. windows下9款一键快速搭建PHP本地运行环境的好工具(含php7.0环境)

    推荐几款一键快速搭建PHP本地运行环境的好工具(含php7.0及apache,nigix,mysql) 首推phpstudy2016和wampServer3.0.6     理由支持php7.0 目前 ...

  2. Python学习笔记_Chapter 7web开发

    1.web应用元素 a.成员: web浏览器 web服务器 b.行为: web请求: 请求内容: 静态内容:如html文件,图像. 动态内容:需服务器运行一个程序进而做出响应. 网关接口&CG ...

  3. jquery获取li中的各项属性值attr

    发布新内容时的设计 默认显示一个按钮 如:发布按钮(放在h3字体里面)(鼠标上面时.显示发布到哪个模块下拉菜单发在li里面) $('#pup_model li , #pup_model h3').cl ...

  4. 2.Math对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. lua的string库

    lua支持的所有字符类 .      任意字符 %a   字母 %c 控制字符 %d 数字 %l         小写字母 %p  标点字符 %s 空白符 %u        大写字母 %w   字母 ...

  6. HUST 1352 Repetitions of Substrings(字符串)

    Repetitions of Substrings Description The “repetitions” of a string S(whose length is n) is a maximu ...

  7. ZUFE 1035 字符宽度编码(字符串)

    Time Limit: 1 Sec  Memory Limit: 128 MB Description 你的任务是编写一个程序实现简单的字符宽度编码方法.规则如下:将任何2~9个相同字符的序列编码成2 ...

  8. 关于windows线程同步的四种方法

    #include "stdafx.h" #include "iostream" #include "list" #include " ...

  9. LeetCode OJ combine 3

    public class Solution { public List<List<Integer>> combinationSum3(int k, int n) { retur ...

  10. 【Loadrunner】初学Loadrunner——录制脚本、回放、以及优化

    一.脚本录制(录制) 打开Loadrunner > 选择创建/编辑脚本 > NewScript > 选择协议(单协议.多协议) > Strart Recording >选 ...