因子个数与因子和

题目: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, 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

题意:

  根据唯一分解定理,先将a唯一分解,得a的所有正约数的个数为sum ,
  因为题目说了不会存在c==d的情况,因此sum要除2 去掉重复情况,
  然后枚举小于b的a的约数,拿sum减掉就可以了

数论原理:

  正整数n有素因子分解n=p1^a1*p2^a2*p3^a3*···*pn^an 因子个数=(a1+1)(a2+2)(a3+3) ···(an+n)

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
int prime[maxn]={1,1,0}; 
int prime1[maxn];
int sum,num,cnt;
long long a,b,temp;
void db()    //埃式筛 
{cnt=0;for(int i=2;i<=sqrt(maxn);i++){if(!prime[i]){for(int j=i+i;j<=maxn;j+=i){prime[j]=1;}}}for(int i=2;i<=maxn;i++){if(!prime[i]){prime1[cnt++]=i;}}
}
void reslove()  求所有素因子
{for(int j=0;j<cnt&&prime1[j]<=sqrt(temp);j++){int num=0;if(temp%prime1[j]==0){while(temp%prime1[j]==0){num++;temp/=prime1[j];}sum*=(num+1);}}if(temp>1)    //如果temp不能被整分,说明还有一个素数是它的约数,此时num=1sum*=2;
}
int main()
{db();int t;cin>>t;for(int i=1;i<=t;i++){cin>>a>>b;if(a<b*b)printf("Case %d: 0\n", i);else{sum=1;temp=a;reslove();sum/=2;for(int k=1;k<b;k++){if(a%k==0){sum--;}}printf("Case %d: %d\n",i,sum);}    }return 0;
} 

 



转载于:https://www.cnblogs.com/BYBL/p/10969698.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393417.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何在JavaScript中直观地设计状态

by Shawn McKay肖恩麦凯(Shawn McKay) 如何在JavaScript中直观地设计状态 (How to visually design state in JavaScript) 使用状态机和状态图开发应用程序的路线图 (A roadmap for developing applications with state machines & statecharts) Why does state managemen…

SQL Server 2008 - Cannot set a credential for principal 'sa'.

很久没有用到SQL Server了&#xff0c;今天有幸在帮同事解决一个SQL Server数据连接的问题时突然发现我无法修改我的sa用户的密码了。过程是这样的&#xff1a;一开始我本地的数据库实例是Windows认证方式&#xff0c;我想将它改成Windows和数据库混合认证方式后用sa账户登录&a…

leetcode50. Pow(x, n)(快速幂)

实现 pow(x, n) &#xff0c;即计算 x 的 n 次幂函数。 示例 1: 输入: 2.00000, 10 输出: 1024.00000 代码 class Solution {public double myPow(double x, int n) {long tn;return t>0?Pow(x,t):1/Pow(x,-t);//判断幂指数}public double Pow(double x, long n) {if(n…

Java DES 加解密(DES/CBC/PKCS5Padding)

/*** DES加密** param data 加密数据* param key 密钥* return 返回加密后的数据*/public static byte[] desEncrypt(byte[] data, String key, String charset) {try {Cipher cipher Cipher.getInstance("DES/CBC/PKCS5Padding");byte[] k charset null || char…

mysql 连接池 100_mysql的最大连接数默认是100_MySQL

mysql的最大连接数默认是100, 这个数值对于并发连接很多的数据库应用是远远不够的&#xff0c;可以把它适当调大&#xff0c;mysql的最大连接数默认是100, 这个数值对于并发连接很多的数据库应用是远远不够的&#xff0c;可以把它适当调大&#xff0c;whereis safe_mysqld找到s…

angular上传图片_如何使用Angular轻松上传图片

angular上传图片by Filip Jerga由Filip Jerga 如何使用Angular轻松上传图片 (How to make image upload easy with Angular) This is the second part of the tutorial on how to upload an image to Amazon S3. You can find the first part here. In this article, we will …

Java小知识-----Map 按Key排序和按Value排序

Map排序的方式有很多种&#xff0c;这里记录下自己总结的两种比较常用的方式&#xff1a;按键排序(sort by key)&#xff0c; 按值排序(sort by value)。 1、按键排序 jdk内置的java.util包下的TreeMap<K,V>既可满足此类需求&#xff0c;向其构造方法 TreeMap(Comparator…

社区帖子全文搜索实战(基于ElasticSearch)

要为社区APP的帖子提供全文搜索的功能&#xff0c;考察使用ElasticSearch实现此功能。 ES的安装不再描述。 es集成中文分词器(根据es版本选择对应的插件版本)下载源码&#xff1a;https://github.com/medcl/elasticsearch-analysis-ik  maven编译得到&#xff1a;elasticsear…

Microsoft Deployment Toolkit 2010 新功能实战之一

续Microsoft Deployment Toolkit 2010 Beta 2先睹为快&#xff01;下面将通过使用Microsoft Deployment Toolkit 2010来部署Windows 7来介绍它的新功能的具体操作。有些概念的理解和操作方法参见MDT2008部署之一概览。 一、实验环境操作全部在VMware Workstation的虚拟操作环境…

leetcode1482. 制作 m 束花所需的最少天数(二分法)

给你一个整数数组 bloomDay&#xff0c;以及两个整数 m 和 k 。 现需要制作 m 束花。制作花束时&#xff0c;需要使用花园中 相邻的 k 朵花 。 花园中有 n 朵花&#xff0c;第 i 朵花会在 bloomDay[i] 时盛开&#xff0c;恰好 可以用于 一束 花中。 请你返回从花园中摘 m 束…

sublime 消除锯齿_如何在Sublime中消除麻烦

sublime 消除锯齿by Abdul Kadir通过阿卜杜勒卡迪尔(Abdul Kadir) 如何在Sublime中消除麻烦 (How to lint away your troubles in Sublime) Sublime is a lightweight text editor and is quite popular among many web developers. Now I know there are many sophisticated …

node.js mysql防注入_避免Node.js中的命令行注入安全漏洞

在这篇文章中&#xff0c;我们将学习正确使用Node.js调用系统命令的方法&#xff0c;以避免常见的命令行注入漏洞。我们经常使用的调用命令的方法是最简单的child_process.exec。它有很一个简单的使用模式;通过传入一段字符串命令&#xff0c;并把一个错误或命令处理结果回传至…

Netbackup detected IBM drives as unusable

今天在远程给客户安装NBU的时候&#xff0c;遇到了下面这个问题&#xff0c;下面的内容来至于SYMANTEC。 1&#xff0c;更新mapping文件 在原来也遇到过类型的故障&#xff0c;通过更新mapping文件后&#xff0c;故障解决&#xff0c;这次没有那么幸运了。 2&#xff0c;lsscsi…

opencv python运动人体检测

采用非极大值抑制&#xff0c;将重叠的框合并成一个。 # import the necessary packages from imutils.object_detection import non_max_suppression import numpy as np import imutils import cv2# initialize the HOG descriptor/person detector hog cv2.HOGDescriptor()…

php mysql 注入一句话木马_渗透技术--SQL注入写一句话木马原理

讲一下SQL注入中写一句话拿webshell的原理&#xff0c;主要使用的是 SELECT ... INTO OUTFILE 这个语句&#xff0c;下面是一个语句的例子:SELECT * INTO OUTFILE C:\log1.txt这样就可以把查询到的数据写入到C盘的log1.txt这个文件里面。利用这个原理我们可以把PHP的一句话木马…

开源贡献 计算_使用此网站为开源做贡献

开源贡献 计算When I began the transition into being a software developer, I knew that contributing to open source projects would greatly assist my job search.当我开始过渡为软件开发人员时&#xff0c;我知道为开源项目做贡献将极大地帮助我的求职。 So, I jumped…

leetcode275. H指数 II(二分法)

给定一位研究者论文被引用次数的数组&#xff08;被引用次数是非负整数&#xff09;&#xff0c;数组已经按照升序排列。编写一个方法&#xff0c;计算出研究者的 h 指数。 h 指数的定义: “h 代表“高引用次数”&#xff08;high citations&#xff09;&#xff0c;一名科研人…

java 多线程阻塞队列 与 阻塞方法与和非阻塞方法

Queue是什么队列&#xff0c;是一种数据结构。除了优先级队列和LIFO队列外&#xff0c;队列都是以FIFO&#xff08;先进先出&#xff09;的方式对各个元素进行排序的。无论使用哪种排序方式&#xff0c;队列的头都是调用remove()或poll()移除元素的。在FIFO队列中&#xff0c;所…

批量移动AD用户到指定OU

作为域管理员&#xff0c;在日常工作中使用ADUC&#xff08;AD用户和计算机&#xff09;工具在图形界面中进行账号管理操作可谓是家常便饭了。然而一个个增加、移动、删除用户&#xff0c;这样操作有时真的够烦&#xff0c;当管理大批量的账户时&#xff0c;重复操作浪费的时间…

vs 编译说明

静态编译/MT&#xff0c;/MTD 是指使用libc和msvc相关的静态库(lib)。动态编译&#xff0c;/MD&#xff0c;/MDd是指用相应的DLL版本编译。其中字母含义 d&#xff1a;debug m&#xff1a;multi-threading(多线程) t&#xff1a;text代码 d&#xff1a;dynamic(动态)…