> 웹 프론트엔드 > HTML 튜토리얼 > Codeforces Round #282 (Div. 2)-B. Modular Equations_html/css_WEB-ITnose

Codeforces Round #282 (Div. 2)-B. Modular Equations_html/css_WEB-ITnose

WBOY
풀어 주다: 2016-06-24 11:52:22
원래의
1179명이 탐색했습니다.

Modular Equations

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

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 




题意:给出a,b,问有多少满足a % x == b的正整数x存在。


分析:暴力可解。a % x == b有(a - b) % x == 0,也就是找a - b的因子。前提是:x是正整数,但是要注意需满足x > b(余数比除数小),当a




AC代码:

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define INF 0x7fffffffint main(){    #ifdef sxk        freopen("in.txt","r",stdin);    #endif    int a, b, ans;    while(scanf("%d%d",&a, &b)!=EOF)    {        ans = 0;        if(a  b) ans ++;                    if((a-b)/x > b) ans ++;                }            }            if((a-b) == x*x && x > b) ans ++;            printf("%d\n", ans);        }    }    return 0;}</time.h></stdlib.h></math.h></string></map></set></queue></vector></algorithm></iostream></string.h></stdio.h>
로그인 후 복사



Python版:

a, b = map(int, raw_input().split())if a == b:  print 'infinity'elif a  b:        ans += 1      if a/i > b and i*i != a:        ans += 1    i += 1  print ans
로그인 후 복사






원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿