题意

有一块矩形(也可能是正方形)的飞毯。

给定飞毯的面积\(n\)和最小可能的边长\(a\),求可能有多少种不同边长的飞毯。(\(1<=a<=n<=1e12\))

如面积\(n=6\)时,\(\{2,3\}\)和\(\{3,2\}\)算一种。

题解

本来想\(sqrt(n)\)的复杂度直接枚举\(n\)的所有因数,发现\(TLE\)了。

正解是把\(n\)质因数分解成\(n=a_1^{b_1}a_2^{b_2}...a_n^{b_n}\),然后\(n\)的因子的个数就是\((1+b_1)*(1+b_2)...(1+b_n)\)。

我自做聪明的把上面得出的结果加上\(1\)(考虑到因子有\(1\)的情况),结果WA了一晚上。

得出\(n\)的因子个数之后,再暴力枚举小于\(b\)的数,如果是\(n\)的因数就减掉。

代码

#include <bits/stdc++.h>

#define FOPI freopen("in.txt", "r", stdin)
#define FOPO freopen("out.txt", "w", stdout)
#define FOR(i,x,y) for (int i = x; i <= y; i++)
#define ROF(i,x,y) for (int i = x; i >= y; i--) using namespace std;
typedef long long LL;
const int N = 1e6 + 10; int Prime[N+100]; void getPrime(int N)
{
memset(Prime, 0, sizeof(Prime));
FOR(i, 2, N)
{
if (!Prime[i]) Prime[++Prime[0]] = i;
for (int j = 1; j <= Prime[0] && Prime[j] <= N/i; j++)
{
Prime[Prime[j]*i] = 1;
if (i % Prime[j] == 0) break;
}
}
} int factor[N+100][2]; int facCnt;
LL Factor(LL x)
{
facCnt = 0;
LL tmp = x;
for (int i = 1; Prime[i] <= tmp/Prime[i]; i++)
{
factor[facCnt][1] = 0;
if (tmp % Prime[i] == 0)
{
factor[facCnt][0] = Prime[i];
while(tmp % Prime[i] == 0)
{
factor[facCnt][1]++;
tmp /= Prime[i];
}
facCnt++;
}
} if (tmp != 1)
{
factor[facCnt][0] = tmp;
factor[facCnt++][1] = 1;
} LL res = 1;
FOR(i, 0, facCnt-1)
res *= (1+factor[i][1]); return res;
} LL n, b;
int t; int main()
{
getPrime(N); scanf("%d", &t);
FOR(ca, 1, t)
{
scanf("%lld %lld", &n, &b);
if (n < b*b)
{
printf("Case %d: 0\n", ca);
continue;
} LL Sum1 = Factor(n) / 2;
FOR(i, 1, b-1)
if (n % i == 0) Sum1--;
printf("Case %d: %lld\n", ca, Sum1);
}
}

LightOJ - 1341 Aladdin and the Flying Carpet(数论)的更多相关文章

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

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

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

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

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

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

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

    http://www.lightoj.com/volume_showproblem.php?problem=1341 题意:给你长方形的面积a,边最小为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【整数分解】

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

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

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

  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 算数基本定理

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

随机推荐

  1. 敏捷开发(Agile development)

    敏捷开发(Agile development) 敏捷开发是一种以人为核心.迭代.循序渐进的开发方法.在敏捷开发中,软件项目的构建被切分成多个子项目,各个子项目的成果都经过测试,具备集成和可运行的特征. ...

  2. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  3. eclipse配置android开发环境并搭建第一个helloWord工程

    一.搭建Android在eclipse下环境    一.JDK(不用安装  下载地址: http://www.xp510.com/xiazai/Application/program/23625.ht ...

  4. FormsAuthentication IsAuthenticated一直为false

    解决办法: 在Web.Config中添加一下红框的内容

  5. 判断dataset表中是否存在 某列

    DataSet ds ; ds.Tables[0].Columns.Contains("a") 同样适用于 datarow dr ; dr.Table.Columns.Contai ...

  6. linux下的tomcat开机自启动(亲测),更改静态ip

    开机自启动Tomcat: 1.修改脚本文件rc.local:vim /etc/rc.d/rc.local 这个脚本是使用者自定的开机启动程序,可以在里面添加想在系统启动之后执行的脚本或者脚本执行命令 ...

  7. es6-async

    含义 ES2017 标准引入了 async 函数,使得异步操作变得更加方便. async 函数是什么?一句话,它就是 Generator 函数的语法糖. 前文有一个 Generator 函数,依次读取 ...

  8. wpf学习之(IValueConverter)

      学习IValueConverter的使用 public class StatuToNullableBoolConverter : IValueConverter { /// <summary ...

  9. jeesit 部署404

    1.刷新项目 2.clean 项目 3.重新部署项目 4.Ran as maven build 后在重新部署 5.重新导入maven项目

  10. shell实现网站备份

    #!/bin/bash ##back web directory scripts #需要备份的目录写入与脚本同级目录test.txt文件中 DIR="/data/server/www&quo ...