Codeforces Round #282 (Div. 2) A B

来源:互联网 发布:5g网络概念股龙头 编辑:程序博客网 时间:2024/04/19 21:04

http://codeforces.com/contest/495

A. Digital Counter
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.

One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.

Suppose the digital counter is showing number n. Malek calls an integer x (0 ≤ x ≤ 99good if it's possible that the digital counter was supposed to show x but because of some(possibly none) broken sticks it's showing n instead. Malek wants to know number of good integers for a specific n. So you must write a program that calculates this number. Please note that the counter always shows two digits.

Input

The only line of input contains exactly two digits representing number n (0 ≤ n ≤ 99). Note that n may have a leading zero.

Output

In the only line of the output print the number of good integers.

Sample test(s)
input
89
output
2
input
00
output
4
input
73
output
15
Note

In the first sample the counter may be supposed to show 88 or 89.

In the second sample the good integers are 000880 and 88.

In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99.

A 打表 ,开始数错了一个WA了

#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<string.h>#include<queue>#include<stack>#include<set>#include<sstream>#include<time.h>#include<utility> #include<malloc.h> using namespace std;char p[5];int q[12] = {2,7,2,3,3,4,2,5,1,2};int main(){    while (cin >> p)    {        int t = int (p[0] - '0');        int tt = int (p[1] - '0');        int ans = q[t] * q[tt];        cout << ans << endl;    }    return 0;}

B. 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
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 




B 优化算法提高效率 以前接触过类似的

#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<vector>#include<string.h>#include<queue>#include<stack>#include<set>#include<map>#include<sstream>#include<time.h>#include<utility>#include<malloc.h>using namespace std;int n, m;int slove(int x ,int y){int ans = 0;for (int i = 1; i*i <= x; i++){if (i * i == x){if (i > y)ans++;}else if (x % i == 0){if (i > y){ans++;}if (x/i > y){ans++;}}}return ans;}int main(){while (cin >> n >> m){int ans = 0;n -= m;if (n == 0){cout << "infinity" << endl;continue;}else if (n < 0){cout << 0 << endl;continue;}else cout << slove (n,m) << endl;}return 0; }



0 0