数论 C - 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, 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
这个题目很明显是唯一分解定理,但是如果你不知道唯一分解定理,那这个其实就有点难。
如果明白这个这个定理,那么这个题目就变得很容易了,这个题目就是运用了这个定理。
题目让你求一个数的分解形式有多少种,且分解成的最小的数要比给定数字大,
那不就是你求出有多少个正因数,然后除以2,这个求的就是对数。
然后减去不满足条件的。
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <queue>
- #include <vector>
- #include <cmath>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- const int maxn = 1e6;
- int v[maxn],isp[maxn], m;
- void init1()
- {
- m = ;
- memset(v, , sizeof(v));
- for (int i = ; i < maxn; i++)
- {
- if (v[i] == )
- {
- isp[m++] = i;
- v[i] = i;
- }
- for (int j = ; j < m; j++)
- {
- if (v[i]<isp[j] || i * isp[j]>maxn) break;
- v[i*isp[j]] = isp[j];
- }
- }
- }
- ll cont(ll x)
- {
- ll sum = ;
- if (x == ) return ;
- for(ll i=;i<m;i++)
- {
- ll num = ;
- while(x%isp[i]==)
- {
- x /= isp[i];
- num++;
- }
- sum *= num + ;
- if (x == ) break;
- }
- if (x > ) sum *= ;
- return sum;
- }
- int main()
- {
- int t, cas = ;
- init1();
- cin >> t;
- while(t--)
- {
- ll a, b;
- cin >> a >> b;
- if(b>=sqrt(a))
- {
- printf("Case %d: %d\n", ++cas, );
- }
- else
- {
- ll cnt = ;
- for(ll i=;i<b;i++)
- {
- if (a%i == ) cnt++;
- }
- ll sum = cont(a) / ;
- ll ans = sum - cnt;
- printf("Case %d: %lld\n", ++cas, ans);
- }
- }
- return ;
- }
数论 C - Aladdin and the Flying Carpet的更多相关文章
- Aladdin and the Flying Carpet (LightOJ - 1341)【简单数论】【算术基本定理】【分解质因数】
Aladdin and the Flying Carpet (LightOJ - 1341)[简单数论][算术基本定理][分解质因数](未完成) 标签:入门讲座题解 数论 题目描述 It's said ...
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...
- Aladdin and the Flying Carpet
Aladdin and the Flying Carpet https://cn.vjudge.net/contest/288520#problem/C It's said that Aladdin ...
- C - Aladdin and the Flying Carpet 有多少种长方形满足面积为a(<=10^12),且最短边>=b;长方形边长为整数,且一定不可以是正方形。
/** 题目:C - Aladdin and the Flying Carpet 链接:https://vjudge.net/contest/154246#problem/C 题意:有多少种长方形满足 ...
- LightOJ1341 Aladdin and the Flying Carpet —— 唯一分解定理
题目链接:https://vjudge.net/problem/LightOJ-1341 1341 - Aladdin and the Flying Carpet PDF (English) S ...
- E - Aladdin and the Flying Carpet
It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a ...
- LightOJ - 1341 Aladdin and the Flying Carpet(数论)
题意 有一块矩形(也可能是正方形)的飞毯. 给定飞毯的面积\(n\)和最小可能的边长\(a\),求可能有多少种不同边长的飞毯.(\(1<=a<=n<=1e12\)) 如面积\(n=6 ...
- [LightOJ 1341] Aladdin and the Flying Carpet (算数基本定理(唯一分解定理))
题目链接: https://vjudge.net/problem/LightOJ-1341 题目描述: 问有几种边长为整数的矩形面积等于a,且矩形的短边不小于b 算数基本定理的知识点:https:// ...
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)
http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...
随机推荐
- 云时代的.NET
编程语言从最初的0101机器码到汇编语言再到面向对象的编程,不断的发展,整个发展趋势呈现高内聚.低耦合.可重用.可理解的特点.最早编程是用机器码,人的大脑不像电脑,无法处理0101:后来汇编语言还是太 ...
- String、StringBuffer和StringBuilder类的区别
Java提供了String.StringBuffer和StringBuilder类来封装字符串,并提供了一系列操作字符串对象的方法. 它们的相同点是都用来封装字符串:都实现了CharSequence接 ...
- IM开发者的零基础通信技术入门(一):通信交换技术的百年发展史(上)
[来源申明]本文原文来自:微信公众号“鲜枣课堂”,官方网站:xzclass.com,原题为:<通信交换的百年沧桑(上)>,本文引用时已征得原作者同意.为了更好的内容呈现,即时通讯网在收录时 ...
- class基本使用
console.log(` 1.创建一个空对象 2.让this 指向刚刚创建好的空对象 3.执行构造函数内的代码 (为相关的属性和方法赋值) 4.返回创建好的对象`) // 1.创建一个空对象 // ...
- Java笔试题库之选题题篇【1-70题】
1.下面中哪两个可以在A的子类中使用:( ) class A { protected int method1 (int a, int b) { return 0; } } A. public int ...
- numpy操作
python中使用了numpy的一些操作,特此记录下来: 生成矩阵,替换值 import numpy as np # 生成一行10列的矩阵 dataset = np.zeros((1, 10)) # ...
- 『集群』007 如何测试Slithice源代码
如何测试Slithice源代码 直接测试 >你可以直接 进入 “集合编译区”,这里面 已经有 编译好的 所有程序集: >部署 配置数据库: >附加 集合编译区 中的 SQLServe ...
- Promise来控制JavaScript的异步执行
一般来说,js.html都是按照从上至下这种方式来进行执行的.这就造成了,基本上所有的执行过程都是在一个线程中进行. 我们都知道,ajax的使用大大的提高了前后台的沟通效率,那么有没有什么方式,让js ...
- (五)surging 微服务框架使用系列之缓存-reids
1.服务跟客户端初始化的时候需要添加缓存配置 var host = new ServiceHostBuilder() .RegisterServices(builder => { builder ...
- 高可用实现KeepAlived原理简介
一.简介 目前主流实现web网站及数据库服务高可用软件包括:keepalived.heartbeat.corosync,cman;高可用简称HA: 官方站点:https://www.keepalive ...