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 ...
随机推荐
- wpf 在不同DPI下如何在DrawingVisual中画出清晰的图形
环境Win10 VS2017 .Net Framework4.7.1 本文仅讨论在DrawingVisual中进行的画图. WPF单位,系统DPI,显示器DPI三者的定义及关系 WPF单位:一 ...
- mysql中的kill
show processlist;查看id, 然后 kill id ; 就行了.
- K8s 平台可以如何处理 Pod 预授权问题
前言 TKEx-CSIG 是基于腾讯公有云 TKE 和 EKS 容器服务开发的内部上云容器服务平台,为解决公司内部容器上云提供云原生平台,以兼容云原生.适配自研业务.开源协同为最大特点. 业务容器上云 ...
- 入门训练 - 蓝桥杯(Python实现)
A+B问题: 题目: 资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 输入A.B,输出A+B. 输入格式 输入的第一行包括两个整数,由空格分隔,分别表示A.B. 输出格式 输出一行, ...
- CTFHub - Web(六)
命令注入: 1.进入页面,测试127.0.0.1, 关键代码: <?php $res = FALSE; if (isset($_GET['ip']) && $_GET['ip'] ...
- oracle释放空间到OS
测试: 建表空间 CREATE TABLESPACE TESTTBS DATAFILE '/oradata01/dfhdb/testtbs01.dbf' SIZE 2G; 在表空间上建表 CREATE ...
- OGG类异常汇总
1.启动ogg后,进程不ABEND也不向前走 原因:ogg启动后,会收集表的统计信息耗费大量时间,导致进程不往前走 解决:在参数文件中加入 SQLEXEC 'alter session set OPT ...
- scp等不需要存入know_host
1.修改sshd的配置文件 vi /etc/ssh/ssh_config 修改为如下 StrictHostKeyChecking no UserKnownHostsFile /dev/null 重启s ...
- VL02N发货过账BAPI
使用BAPI函数: BAPI_OUTB_DELIVERY_CONFIRM_DEC 进行delivery的发货过账,可能会有如此的需求,就是修改实际的发货日期.规划的GI.交货日期.装载日期.传输计划日 ...
- Py基础—变量名,条件循环,空执行,编码,运算符,字符比较,简化写法
变量名 只能是字母,数字,下划线.数字不能开头,不要和python内置的东西重复.赋予变量名内容:name1 = "shit" 输出变量名内容 print(name1) 条件语句 ...