Aladdin and the Flying Carpet LightOJ - 1341(算数基本定理)

LightOJ 1341 - Aladdin and the Flying Carpet(算术基本定理 唯一分解定理) 题目链接:http://lightoj.com/volume_showproblem.php?problem=1341 It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are c 阅读详情

Aladdin and the Flying Carpet

LightOJ - 1341

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

2

10 2

12 2

Sample Output

Case 1: 1

Case 2: 2

算术基本定理又叫唯一分解定理。
算术基本定理内容:任何一个大于1的自然数 ,都可以唯一分解成有限个质数的乘积 这里写图片描述 ,这里 这里写图片描述均为质数,其中指数 ai是正整数。


算术基本定理的几个应用:
下面的p1,p2…pn都是素数。
这里写图片描述

同时全体正因数的和也可以写作:
这里写图片描述


本题就是第一个应用。
有几个注意的地方:获得质数的个数的时候,可以先不筛选素数,但是本题时间卡的紧,必须要先筛素数。还有注意当b*b>=a的时候就特判。


最后把总的个数除2然后减去因数小于要求的最小因数的情况

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int MAXN = 1e6+10;
int t;
int primes[MAXN];
bool isprime[MAXN];
void getPrime(){
    memset(isprime,true,sizeof(isprime));
    isprime[0] = isprime[1] = false;
    t = 0;
    for(int i = 2; i < MAXN; i++){
        if(isprime[i]){
            primes[t++] = i;
            for(int j = i + i; j < MAXN; j += i){
                isprime[j] = false;
            }
        }
    }
    return;
}
int getfac(ll x){
    int ans = 1;
    for(int i = 0; i < t && primes[i] * primes[i] <= x; i++){
        if(x == 1) break;
        int tmp = 0;
        while(x % primes[i] == 0){
            tmp++;
            x /= primes[i];
        }
        ans *= (tmp + 1);
    }
    if(x != 1) ans *= 2;//ans = ans * (1 + 1);
    return ans;
}
int main(){
    getPrime();
    int t;
    int cas = 0;
    scanf("%d",&t);
    while(t--){
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if(b * b >= a){//因为题目要求不是正方形,并且另一条边一定大于b
            printf("Case %d: 0\n",++cas);
            continue;
        }
        int ans = getfac(a);
        ans /= 2;//因子对,所以除2
        for(int i = 1; i < b; i++){
            if(a % i == 0) ans--;//将小于要求的最小因数的情况去掉
        }
        printf("Case %d: %d\n",++cas,ans);
    }
    return 0;
}


深入瑞芯微SDK:手把手解析Uboot、Kernel到Rootfs的镜像生成与烧录 本文深入解析瑞芯微SDK中从Uboot、Kernel到Rootfs的镜像生成与烧录全流程,揭示编译背后的技术细节。通过详细分析SDK架构、镜像生成流水线、分区表定制、Rootfs构建及烧录科学,帮助开发者从会编译进阶到懂原理,掌握系统级开发的关键技术。 阅读详情

相关推荐

无人机信号干扰系统设计方案

设计定向阻塞干扰器需要结合射频(RF)技术、功率放大技术和定向天线技术,核心目标是向特定方向发射高功率噪声信号,覆盖目标频段,阻断无人机的通信或导航信号。实际设计中需平衡功率、效率、散热和便携性,同时需考虑抗干扰技术的快速演进(如无人机加密通信和AI避障)。在合法框架下,此类设备可有效应对“黑飞”威胁,但技术滥用风险需严格管控。定向阻塞干扰器的硬件设计核心在于。

wanghao312的博客 3059

Aladdin and the Flying Carpet---阿拉丁和飞毯

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 mag...

嵩韵儿 710

基于PID算法的循迹小车

这一期为创客们带来基于PID算法的循迹小车制作 1.标准赛道示意图: (该赛道包含了:左直角、右直角、十字路口等路况) 2.灰度传感器安装示意图: (可根据实际情况调节各传感器之间的间距) 3.硬件原理图: 4.控制逻辑: 5.程序如下: #define leftA_PIN 7 #define leftB_PIN 6 #define left_Pwm_PIN 5 #define STBY...

qq_44343584的博客 4万+

lightOj 1341Aladdin and the Flying Carpet 算数基本定理

1341 - Aladdin and the Flying Carpet PDF (English) Statistics Forum Time Limit:3 second(s) Memory Limit:32 MB It's said that Aladdin had to solve seven m...

weixin_34235457的博客 229

Python程序—定子故障三相永磁同步电动机振动与电流数据集

1.0 kW 电机匝间短路故障数据: 正常匝间短路振动数据: 匝间短路故障,严重度为2.26%: 匝间短路故障,严重度为2.70%: 匝间短路故障,严重度为3.35%: 匝间短路故障,严重度为4.41%: 匝间短路故障,严重度为6.48%: 匝间短路故障,严重度为12.17%: 匝间短路故障,严重度为21.69%1.5 kW 电机匝间短路故障数据: 正常匝间短路振动数据: 匝间短路故障,严重度为1.57%: 匝间短路故障,严重度为1.88%: 匝间短路故障,严重度为2.34%

m0_66465741的博客 1316

手把手教你使用YOLOv11模型,训练自己数据集,百分百成功(无废话)

YOLOV11百分百成功训练自己的数据集并进行图像、视频流脚本预测

chenhenGzzz的博客 1951

Aladdin and the Flying Carpet(唯一分解定理)

LightOJ - 1341 Aladdin and the Flying Carpet 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, le

kitalekita的博客 413

摄像头模组选型避坑指南:如何根据Sensor和Lens参数匹配最佳组合

本文深入解析摄像头模组选型中Sensor与Lens的核心参数匹配要点。重点阐述了主光线角(CRA)匹配对边缘画质的关键影响,并提供了传感器尺寸、像素尺寸、焦距、光圈等参数的协同选型策略与实战避坑指南,帮助工程师在手机、安防、车载等不同应用场景下实现性能与成本的最佳平衡。

ee345的博客 617

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

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 magic...

在读NLP硕士 478

告别硬件!用Wokwi在线模拟ESP32点灯,5分钟搞定开发环境搭建

本文介绍如何使用Wokwi在线模拟器快速搭建ESP32开发环境,5分钟内完成点灯实验。无需硬件即可体验GPIO控制、PWM调光等核心功能,特别适合物联网开发初学者和快速原型验证。Wokwi的零成本、全功能模拟特性让嵌入式开发变得前所未有的简单高效。

weixin_42567497的博客 493

知识图谱开发实战:搭建上市公司知识图谱(二)

搭建上市公司知识图谱(二)学习目标1. 获取上市公司公开数据1.1 获取上市公司列表与行业信息1.2 代码展示2. 从网站爬取上市公司网页并存储为 HTML文件2.1 准备环境2.2 爬取上市公司公开信息3. 解析HTML文件,获取高管信息并存储为 csv 文件4. 设计知识图谱数据库4.1 实体4.2 关系4.3 属性4.4 特殊4.5 代码5. 知识图谱数据库查询实战5.1 实战:按照neo4j的数据格式,转换CSV文件5.2 实战:使用neo4j-admin 导入数据5.3 实战:使用neo4j-b

全网粉丝30W+,优快云、稀土掘金人工智能领域签约作者,人工智能、大模型、Python 爬虫,商务合作,请私信沟通。 2093

Aladdin and the Flying Carpet [整数分解]

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

chutzpah 688

目标跟踪与视频时序分析基础

两帧均有目标,却因快速移动导致检测框无重叠,仅靠交并比(IoU)无法维持身份关联。本文通过手算与纯Python实现最小跟踪流程,揭示IoU仅为位置线索,不能应对快速位移或遮挡。实验表明,即使目标真实存在,低重叠也会触发新编号。强调跟踪需结合运动预测、外观特征与阈值验证,避免误判。

Mr数据杨 2335

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

[LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理)) 题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https://baike.baid...

Youpeng 325

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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

根据第一个定理,先求出 正因数的个数,再除以二 就是类型数,因为题目说了不为正方形。 要求小于b,则从 1 到 b-1 枚举a的约数,每次找到就少一种类型 当 b>= sqrt(a)时,ans = 0 //LightOJ 1341 - Aladdin and the Flying Carpet //算数基本定理 #include <bits/stdc++.h> #d...

恒持此志成永志 204

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

【算数基本定理(唯一分解定理)】Aladdin and the Flying Carpet LightOJ - 1341

Think: 1知识点:算数基本定理(唯一分解定理) 算术基本定理的几个应用: 注:p1, p2, pi都是素数 同时全体正因数的和也可以写作: ——“算数基本定理”参考博客地址2题意:输入a, b(1 ≤ b ≤ a ≤ 1e12),a代表一个矩形的面积,b表示矩形中最小的那条边至少长度为b,询问有多少个符合条件的矩形 注:题意要去本题目中的矩形不是正方形 3解题思路:

BlessingXRY的博客 709

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

LightOJ Aladdin and the Flying Carpet 1341【算数基本定理+几何】

1341 - Aladdin and the Flying Carpet PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB It's said that Aladdin had to solve seven my

豫帝哥哥 1979

LightOj1341_Aladdin and the Flying Carpet_算数基本定理

题意有一个矩形,它不是正方形,并且它得较短边不能小于 k ,给出它得面积 n,求满足要求的矩形的数目。

弱的奋斗之旅 326

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

题目大意:给出面积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...

weixin_30634661的博客 88

lightoj 1341 Aladdin and the Flying Carpet(算术基本定理)题解

题意:给一个矩形(非正方形)面积a和最小边长b,要求边长均大于b,求这样的矩形有几个思路:先用到了之前学的质因数分解,还有一个新的公式:然后我们可以先算出a的所有约数,因为只算约数个数面积重复,所以要/2;然后暴力出<b的所有约数减去。技巧:1.用save[i]*save[i]<=temp剪枝 2.要注意判断出循环的ans是否大于1,如果大于1则表示还...

weixin_34352449的博客 135

LightOJ 1341 Aladdin and the Flying Carpet

LightOJ 1341 Aladdin and the Flying Carpet 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 mys...

旺崽的博客 2404

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

算术基本定理:一个非质数,可以分解唯一有限个质数的乘积。 N=P1^r1 * P2^r2 *P3^r3*...*Pn^rn (P1<P2<P3<...<PN & Pi 是质数 & ri>=0) N的正因子个数为num=(a1+1)*(a2+1)........*(an+1),即为每个质数的质数+1的乘积。 核心思想: 对素数进行打表,将素数存...

智慧园子的代码世界 338
上一篇: Prime Independence LightOJ - 1356(质因子分解+最大点独立集)
下一篇: The Modcrab (简单模拟)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值