题目大意:给出面积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. [SOJ]1753 解码

    1753. 解码 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description ZX是另一头04级的牛,他现在在UPen.他跟LLK经 ...

  2. uhttpd配置文件分析

    文件位于 /etc/config/uhttpd. root@hbg:/etc/config# cat uhttpd config uhttpd 'main'        list listen_ht ...

  3. delphi中ShellExecute使用详解

    http://jingyan.baidu.com/article/ae97a646ae00a2bbfd461d38.html 百度的讲解 http://www.cnblogs.com/del/arch ...

  4. HDU 1264 Counting Squares(模拟)

    题目链接 Problem Description Your input is a series of rectangles, one per line. Each rectangle is speci ...

  5. 消息同步调用-- ESFramework 4.0 进阶(07)

    分布式系统的构建一般有两种模式,一是基于消息(如Tcp,http等),一是基于方法调用(如RPC.WebService.Remoting).深入想一想,它们其实是一回事.如果你了解过.NET的Prox ...

  6. C# 语言规范_版本5.0 (第3章 基本概念)

    1. 基本概念 1.1 应用程序启动 具有入口点 (entry point) 的程序集称为应用程序 (application).应用程序运行时,将创建新的应用程序域 (application doma ...

  7. LeetCode OJ 42. Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  8. Payoneer官网注册教程,免费申请美国银行账号

    在我搞网赚项目的过程中,碰到境外收款付款的问题,起初我用Paypal贝宝,手续费高得惊人!相信做电商外贸的朋友深有体会.幸而发现了Paypal替代产品Payoneer,注册简单,手续费低,还有中文网站 ...

  9. 放弃阿里云主机,选择高性价比Vultr VPS免备案

    阿里云主机ECS推广多年后,质量有所改善,但我依然强烈不推荐阿里云主机.考虑性价比带宽速度等因素后,我推荐的vps品牌有vultr和digitalocean,还有大名鼎鼎的linode,是中国用户的最 ...

  10. Openjudge-计算概论(A)-单词倒排

    描述: 编写程序,读入一行英文(只包含字母和空格,单词间以单个空格分隔),将所有单词的顺序倒排并输出,依然以单个空格分隔. 输入输入为一个字符串(字符串长度至多为100).输出输出为按要求排续后的字符 ...