B. Modular Equations
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.
In the only line of the input two space-separated integers a and b (0 ≤ a, b ≤ 109)
are given.
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 .
21 5
2
9435152 272
282
10 10
infinity
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的更多相关文章
- codeforces 495B. Modular Equations 解题报告
题目链接:http://codeforces.com/problemset/problem/495/B 题目意思:给出两个非负整数a,b,求出符合这个等式 的所有x,并输出 x 的数量,如果 ...
- 数学 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 ...
- [转载] Conv Nets: A Modular Perspective
原文地址:http://colah.github.io/posts/2014-07-Conv-Nets-Modular/ Conv Nets: A Modular Perspective Posted ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- A.Kaw矩阵代数初步学习笔记 5. System of Equations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- [家里蹲大学数学杂志]第269期韩青编《A Basic Course in Partial Differential Equations》 前五章习题解答
1.Introduction 2.First-order Differential Equations Exercise2.1. Find solutons of the following inti ...
- [ACM_其他] Modular Inverse [a关于模m的逆 模线性方程]
Description The modular modular multiplicative inverse of an integer a modulo m is an integer x such ...
- Represent code in math equations
Introduce The article shows a way to use math equations to represent code's logical. Key ideas logic ...
- EM basics- the Maxwell Equations
All the two important problems that the EM theory trys to describe and explain are propogation and r ...
随机推荐
- C语言实现蛇形矩阵
今天大一考试C语言的时候看见了这道题,下面是我转载的一个大佬的博客,自认为分析的很清楚,特来分享一下. **原文地址: https://blog.csdn.net/jack22333/article/ ...
- java调用js代码
jdk8里使用脚本引擎调用js 1.定义一个js方法: function getRouteInfo(province){ //注意,参数不要带var..在java里执行会报错.. if (provin ...
- python面向对象基础-属性/方法
- 【Problems】:JSON parse error: Invalid UTF-8 start byte 0xbd;
简单记录一下 ,我本地开发环境这样写测试时没有问题, @ApiOperation(value="取消关注") @PostMapping("cancelFollow&quo ...
- 【linux】系统编程-6-POSIX标准下的信号量与互斥锁
目录 前言 8. POSIX信号量 8.1 概念 8.2 POSIX无名信号量 8.3 POSIX有名信号量 8.4 POPSIX信号量与system V信号量的区别 9. POSIX互斥锁 9.1 ...
- uni-app 微信小程序 picker 三级联动
之前做过一个picker的三级联动功能,这里分享代码给大家 具体代码: // An highlighted block <template> <view> <picker ...
- java之 Request
0x01.Request 什么是request 在Servlet API中,定义了一个HttpServletRequest接口,它继承自ServletRequest接口,专门用来封装HTTP请求消息. ...
- 从零开始学spring源码之ioc预热:bean的拓展和beanProcessor注册
上篇聊完了bean的解析,说起来做的事情很简单,把xml文件里面配置的标签全部解析到spring容器里面,但是spring做的时候,花了那么大代价去做,后面看看到底值不值得呢. 接下来看看prepar ...
- ovsdb-client命令
ovsdb-server 的命令行接口. 查看有哪些数据库: ovsdb-client list-dbs [server] 查看数据库 schema: ovsdb-client get-schema ...
- 登陆的时候出现javax.xml.bind.DatatypeConverter错误
错误详情: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/Da ...