Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define i modulo j as
the remainder of division of i by j and denote it
by .
A Modular Equation, as Hamed's teacher described, is an equation of the form  in
which a and b are two non-negative integers and x is
a variable. We call a positive integer x for which  asolution of
our equation.

Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.

Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers a and b determines
how many answers the Modular Equation  has.

Input

In the only line of the input two space-separated integers a and b (0 ≤ a, b ≤ 109)
are given.

Output

If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation .

Sample test(s)
input
21 5
output
2
input
9435152 272
output
282
input
10 10
output
infinity
Note

In the first sample the answers of the Modular Equation are 8 and 16 since 

这题的题意是求(n-m)比m大的因数个数,如果直接求会超时,所以可以用循环从1到i*i<=n-m;然后判断当前i和(n-m)/i是否大于m.

#include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,num,t;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==m){
printf("infinity\n");continue;
}
num=0;
for(i=1;i*i<=n-m;i++){
if((n-m)%i==0){
t=(n-m)/i;
if(t>m)num++;
if(i>m && i!=t)num++;
}
}
printf("%d\n",num);
}
}

B. Modular Equations的更多相关文章

  1. codeforces 495B. Modular Equations 解题报告

    题目链接:http://codeforces.com/problemset/problem/495/B 题目意思:给出两个非负整数a,b,求出符合这个等式      的所有x,并输出 x 的数量,如果 ...

  2. 数学 Codeforces Round #282 (Div. 2) B. Modular Equations

    题目传送门 题意:a % x == b,求符合条件的x有几个 数学:等式转换为:a == nx + b,那么设k = nx = a - b,易得k的约数(>b)的都符合条件,比如a=25 b=1 ...

  3. [转载] Conv Nets: A Modular Perspective

    原文地址:http://colah.github.io/posts/2014-07-Conv-Nets-Modular/ Conv Nets: A Modular Perspective Posted ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. A.Kaw矩阵代数初步学习笔记 5. System of Equations

    “矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...

  6. [家里蹲大学数学杂志]第269期韩青编《A Basic Course in Partial Differential Equations》 前五章习题解答

    1.Introduction 2.First-order Differential Equations Exercise2.1. Find solutons of the following inti ...

  7. [ACM_其他] Modular Inverse [a关于模m的逆 模线性方程]

    Description The modular modular multiplicative inverse of an integer a modulo m is an integer x such ...

  8. Represent code in math equations

    Introduce The article shows a way to use math equations to represent code's logical. Key ideas logic ...

  9. EM basics- the Maxwell Equations

    All the two important problems that the EM theory trys to describe and explain are propogation and r ...

随机推荐

  1. 【C++】《C++ Primer 》第十二章

    第十二章 动态内存 目前为止,所使用的对象都有着严格定义的生存期. 全局对象在程序启动时分配,在程序结束时销毁.局部自动对象在进入其定义所在的程序块时被创建,在离开块时销毁.局部static对象在第一 ...

  2. Head First 设计模式 —— 14. 复合 (Compound) 模式

    复合模式 在一个解决方案中结合两个或多个模式,以解决一般或重复发生的问题. P500 思考题 public interface Quackable { public void quack(); } p ...

  3. URL重定向 - Pikachu

    概述: 不安全的url跳转问题可能发生在一切执行了url地址跳转的地方.如果后端采用了前端传进来的(可能是用户传参,或者之前预埋在前端页面的url地址)参数作为了跳转的目的地,而又没有做判断的话就可能 ...

  4. SAP中的事务锁

    我们知道sap中的事物锁tcode是SM01. 细细研究发现,其实无外乎就是将tstc表中的事务码对应的字段CINFO的值加上HEX20 解锁就是还原成原来的值. 当然也发现了,调用了一个系统函数AU ...

  5. 1.5V转5V的最少电路的芯片电路图

    PW5100满足1.5V转5V的很简洁芯片电路,同时达到了最少的元件即可组成DC-DC电路1.5V转5V的升压转换器系统. PW5100在1.5V转5V输出无负载时,输入效率电流极低,典型值10uA. ...

  6. RESTful风格、异常处理、Spring框架

    1.RESTful风格 什么是RESTful风格? REST是REpressentational State Transfer的缩写,中文翻译为表述性状态转移,REST是一种体系结构,而HTTP是一种 ...

  7. STL_deque容器

    一.deque简介 deque是"double-ended queue"的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的. deque在接口 ...

  8. 如何将python中pip源设置为国内源

    1.Windows Python的学习过程中,往往会学习到很多库,而安装各类库的时候,往往不尽人意,下载速度从几KB到十几KB.甚至下载到一半还超时报错.这都是因为pip源是访问国外的官方源,如果需要 ...

  9. 亿级用户下的新浪微博平台架构 前端机(提供 API 接口服务),队列机(处理上行业务逻辑,主要是数据写入),存储(mc、mysql、mcq、redis 、HBase等)

    https://mp.weixin.qq.com/s/f319mm6QsetwxntvSXpKxg 亿级用户下的新浪微博平台架构 炼数成金前沿推荐 2014-12-04 序言 新浪微博在2014年3月 ...

  10. 使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理

    使用Linux服务器来通过网络安装和激活Windows 7 -- 一些基本原理 https://www.pufengdu.org/blog/?p=372