LightOJ 1341 - Aladdin and the Flying Carpet

简介:

1341 - Aladdin and the Flying Carpet
Time Limit: 3 second(s) Memory Limit: 32 MB

It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned about the first mystery.

Aladdin was about to enter to a magical cave, led by the evil sorcerer who disguised himself as Aladdin's uncle, found a strange magical flying carpet at the entrance. There were some strange creatures guarding the entrance of the cave. Aladdin could run, but he knew that there was a high chance of getting caught. So, he decided to use the magical flying carpet. The carpet was rectangular shaped, but not square shaped. Aladdin took the carpet and with the help of it he passed the entrance.

Now you are given the area of the carpet and the length of the minimum possible side of the carpet, your task is to find how many types of carpets are possible. For example, the area of the carpet 12, and the minimum possible side of the carpet is 2, then there can be two types of carpets and their sides are: {2, 6} and {3, 4}.

Input

Input starts with an integer T (≤ 4000), denoting the number of test cases.

Each case starts with a line containing two integers: a b (1 ≤ b ≤ a ≤ 1012) where a denotes the area of the carpet and b denotes the minimum possible side of the carpet.

Output

For each case, print the case number and the number of possible carpets.

Sample Input

Output for Sample Input

2

10 2

12 2

Case 1: 1

Case 2: 2

 


题目大意:
给定T组数据,每组数据有两个数 面积s 和 矩形的宽 a,让你求的是在面积s一定的情况下,假设长和宽分别为a 和 b,最小的边长 >= a的有几种方式可以组成矩形(不是正方形)

解析一下样例:
面积为12 ,最小的边长为2:
首先将12进行素因子分解12 = 2^2*3,所以我们能够得到 
12 = 1 * 12(不符合条件 最小的边长<2)
12 = 2 * 6(符合)
12 = 3 * 4(符合)
所以有 2 种方式,输出 2


解题思路:
每次做题的时候先要考虑一下能不能暴力(暴力简单),这个题如果我们要暴力的话肯定会超时,所以就不要暴力了
通过上述的样例分析,我们也知道了我们首先要做的就是将 面积 s 进行素因子分解,这就用到了唯一分解定理,
s = p1^e1 * p2^e2 *……* pk^ek,我们要得到的是因子的个数,这里所说的因子个数默认为正的,得到因子个数的方法是 num = (e1+1) * (e2+1) * ... *(ek+1),然后又因为没有正方形,而且我们要得到的是有多少对,所以将 num除以2,就得到了可以组成矩形面积为 s 的矩形个数,然后我们只需要在 [1,a)的区间内(注意区间开闭)将 s 的因子减掉就行了(num--),这样就可以了。

上代码:
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long LL;
const int MAXN = 1e6+5;
bool prime[MAXN];
LL p[MAXN],k;
void isprime()
{
    memset(prime, true, sizeof(prime));
    prime[1] = false;
    k = 0;
    for(LL i=2; i<MAXN; i++)
    {
        if(prime[i])
        {
            p[k++] = i;
            for(LL j=i*i; j<MAXN; j+=i)
                prime[j] = false;
        }
    }
}

LL Solve(LL m)
{
    LL ret = 1;
    for(LL i=0; p[i]*p[i]<=m&&i<k; i++)
    {
        LL cnt = 0;
        if(m%p[i] == 0)
        {
            while(m%p[i] == 0)
            {
                cnt++;
                m /= p[i];
            }
            ret *= (cnt+1);
        }
    }
    if(m > 1)
        ret *= 2;
    return ret;
}
int main()
{
    isprime();
    int T;
    cin>>T;
    for(int cas=1; cas<=T; cas++)
    {
        LL s,a;
        cin>>s>>a;
        if(a*a >= s)
            printf("Case %d: 0\n",cas);
        else
        {
            LL ret = Solve(s);
            ret /= 2;
            for(LL i=1; i<a; i++)
                if(s % i == 0)
                    ret--;
            printf("Case %d: %lld\n",cas,ret);
        }
    }
    return 0;
}



目录
相关文章
|
8天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
9504 25
|
8天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
2739 14
|
3天前
|
人工智能 安全 应用服务中间件
NGINX 爆出两处高危漏洞 可导致未经身份验证的远程代码执行
NGINX曝出两个高危漏洞(CVE-2026-123633和CVE-2026-123007),CVSS 9.2分,均属HTTP/2内存安全缺陷,无需认证即可远程执行代码。影响自2015年起的多个版本,静态站点亦受威胁。修复版本为开源版1.30.7/1.31.9。(239字)
1311 1
NGINX 爆出两处高危漏洞 可导致未经身份验证的远程代码执行
|
6天前
|
传感器 安全 区块链
Windows 电脑运行安卓应用教程:开源工具 ApkStart 双击 APK 即装、独立窗口运行
ApkStart 是一款开源Windows工具,让安卓APP像原生软件一样运行:双击APK即安装、生成真实图标、独立窗口启动、开始菜单可搜索。无需传统模拟器,内置QEMU运行时,支持数据互通、ARM兼容与命令行操作。(239字)
|
11天前
|
人工智能 前端开发 API
阿里云Qwen4-Max 大模型详解:定位、特征、能力、适用场景与相对Qwen3-Max差异解析
2026年11月11日,阿里发布第四代旗舰模型Qwen4-Max预览版,首发千问AI平台Token Plan并接入千问办公、Qoder等入口。该版本聚焦知识理解、世界感知、编程与Agentic四项升级,主打复杂编程、专业办公、前端设计与专业软件操作等真实任务。预览期为11月11日10:00至11月25日24:00,仅支持Token Plan调用,到期后模型标识下线;限时2折、新用户再享5折,最低1折可体验。
|
11天前
|
JSON 前端开发 API
阿里云最新Qwen4-Max大模型介绍:模型定位、特征、能力、适用场景解析
2026 年 11 月 11 日,阿里发布第四代旗舰模型Qwen4-Max预览版,首发千问 AI 平台 Token Plan,并同步接入千问办公、Qoder 等入口。该版本聚焦知识理解、世界感知、编程与 Agentic 四项升级,主打复杂编程、专业办公、前端设计与专业软件操作。预览期至 11 月 25 日 24:00,到期后模型标识下线;限时 2 折、新用户再享 5 折,最低 1 折可体验。
|
23天前
|
Linux 开发工具 iOS开发
Codex保姆级教程(下载+安装+登录+使用,含所有版本,2026最新)
Codex是OpenAI推出的开源AI编程智能体,本地运行,可理解整个代码库,支持自然语言指令改代码、执行命令、跑测试、修Bug,兼容Win/macOS/Linux。(239字)
11482 59
|
6天前
|
人工智能 弹性计算 开发工具
零成本玩各大模型!DeepSeek Harness dsh-our-free-model 插件,13 个厂商模型直接用
总结一下:装这个插件,你不用注册、不用绑卡、不用填一个 Key,就能在 DeepSeek Harness 里用上 DeepSeek V4.1 Flash、Kimi K3 这一批前沿模型,而且是白嫖的、还不限量。三步搞定:下载插件,复制包含 `package.json` 的插件目录路径,在「添加插件」里粘贴路径安装并重启。无论是在阿里云 ECS 上通过命令行部署的 Web 版,还是本地的 Electron 桌面端,都能顺利跑通,快速搭建一套零成本的免费模型使用环境。
1378 1
|
4天前
|
人工智能 弹性计算 IDE
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
适合团队落地代码规范,每次提交自动生成评审报告,降低人工CR工作量。同时支持自定义技能脚本,接入团队内部SDK说明文档,让Codex生成符合团队编码规范的代码。Codex三大客户端覆盖本地开发、服务器远程编码、自动化流水线场景,搭配阿里云百炼的Token Plan、Coding Plan,能够低成本搭建稳定可控的AI编码助手。新手建议先从IDE插件入手,熟悉交互逻辑,再尝试CLI版本部署在阿里云ECS,实现云上项目远程编码、批量脚本处理。只要按照步骤完成环境准备、版本选型、密钥对接、项目初始化,就可以把Codex融入日常开发流程,大幅提升代码编写、问题排查、项目重构的效率。
955 0
|
9天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。