codeforces 495B - Modular Equations

Myth丶恋晨 2022-09-24 05:22 250阅读 0赞

codeforces 495B - 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 31ce2070d76a6be7a97b23b7f586bdfd7b839e02.png. A Modular Equation, as Hamed’s teacher described, is an equation of the form f51bed1f32b6c000518c1f920966628d5879013d.png in which a and b are two non-negative integers and x is a variable. We call a positive integer x for which f51bed1f32b6c000518c1f920966628d5879013d.png 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 f51bed1f32b6c000518c1f920966628d5879013d.png 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 f51bed1f32b6c000518c1f920966628d5879013d.png.

Examples

input

  1. 21 5

output

  1. 2

input

  1. 9435152 272

output

  1. 282

input

  1. 10 10

output

  1. infinity

Note

In the first sample the answers of the Modular Equation are 8 and 16 since 6705dfd7e46cb79317f20876cb2fdbb3cd256e26.png

题目链接: 点击打开链接

给出a,b 计算有多少x 满足 f51bed1f32b6c000518c1f920966628d5879013d.png

代码:

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int a,b;
  6. while(~scanf("%d %d",&a,&b))
  7. {
  8. if(b==a)
  9. {
  10. printf("infinity\n");
  11. continue;
  12. }
  13. int ans=0;
  14. for(int i=1;i<sqrt(a-b);i++)
  15. {
  16. if((a-b)%i==0)
  17. {
  18. if(i>b)
  19. ans++;
  20. if((a-b)/i>b)
  21. ans++;
  22. }
  23. }
  24. if((int)sqrt(a-b)*(int)sqrt(a-b)==(a-b)&&sqrt(a-b)>b)
  25. ans++;
  26. printf("%d\n",ans);
  27. }
  28. return 0;
  29. }

发表评论

表情:
评论列表 (有 0 条评论,250人围观)

还没有评论,来说两句吧...

相关阅读