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. at定时任务

    1)at是只执行一次,执行完后任务删除.at的守护进程atd会以后台模式运行,检查作业队列来运行.2)默认 atd每60秒巡逻一次,有作业时候,检查作业时间,如果和当前时间一样,就执行任务3)在使用a ...

  2. kubernets之pod的标签

    一     如何查看pod 的日志 1 通过执行命令查看日志信息 kubectl logs pod_name 二    创建带有标签的pod,一个范例的pod创建yaml文件如下所示 2.1 创建带有 ...

  3. git创建分支并关联远程分支

    1.新建本地分支: 如图,再输入你的分支名字,然后选择从哪个远程分支拉代码,如选择master 至此本地分支创建完成. 2.关联远程分支: (1).先输入git branch -vv,看看分支与远程分 ...

  4. logicaldisk本地磁盘管理

    在网上搜了很多,但是基本都是一样的,差不多都是互相转载摘抄,就那么几个寥寥无几的例子,所以我冒了很大的风险,自己经过多次的测试,对这个命令有了一些新的认识!拿出来分享一下! LOGICALDISK   ...

  5. 03--Docker 容器和镜像常用命令

    一.帮助命令 docker version docker info docker --help =====================镜像命令=========================== ...

  6. [Usaco2016 Dec]Counting Haybales

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=4747 先将原数组排序,然后二分查找即可.时间复杂度\(O((N+Q)logN)\). #i ...

  7. [CPP] STL 简介

    STL 即标准模板库(Standard Template Library),是 C++ 标准库的一部分,里面包含了一些模板化的通用的数据结构和算法.STL 基于模版的实现,因此能够支持自定义的数据结构 ...

  8. Spider爬虫基础

    get获取某个网站的html代码,post访问网站获取网站返回的信息 import urllib.request import urllib.parse #使用get请求 def start1(): ...

  9. Linux 下安装 JDK

    JDK 依赖包: yum install glibc.i686 卸载原有的 JDK 查看本机已安装软件:rpm -qa 查看与java相关的软件:rpm -qa | grep java 删除自带软件: ...

  10. 新型赌博黑产攻击肆虐网吧: LOL博彩引流+棋牌盗号

    https://mp.weixin.qq.com/s/BxnovV6jKqPkYfHEzjd_FA 新型赌博黑产攻击肆虐网吧: LOL博彩引流+棋牌盗号 看雪学院 2019-04-21