版权声明:转载请注明出处。 https://blog.csdn.net/u014427196/article/details/42194077

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 of 88 . 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_ ≤ 99 ) good 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 00 , 08 , 80 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

a solution 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_ ≤ 10 9 ) 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; 
}