您的位置:首页 > 其它

URAL 1157. Young Tiler (数学啊 )

2015-03-22 20:17 344 查看
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1157


1157. Young Tiler

Time limit: 1.0 second

Memory limit: 64 MB

One young boy had many-many identical square tiles. He loved putting all his tiles to form a rectangle more, than anything in the world — he has learned the number of all rectangles he can form using
his tiles. On his birthday he was presented a number of new tiles. Naturally, he started forming rectangles from these tiles — the thing he loved most of all! Soon he has learned all rectangles he could form with a new number of tiles.

Here we should notice that boy can easily count the number of rectangles, but he has difficulty counting the number of tiles — there are too much of them for such a young boy. But it will not be difficult
for you to determine how many tiles he has now, knowing how many rectangles he could form before, how many rectangles he can form now, and how many tiles he got as a birthday present.

You are given numbers M, N and K. You should find the smallest number L, such as you can form Ndifferent rectangles using all L tiles, and form M rectangles
using L − K tiles.

Input

One line containing three integers: M, N, K (1 ≤ M, N, K ≤ 10000).

Output

If L is less than or equal to 10000, then print that number (if there is a number of such L, you should print the smallest one). If there is no solution or smallest L is greater
than 10000, print 0.

Sample

inputoutput
2 3 1

16


题意:

一个年轻的瓦工,用很多瓦片拼矩形,给出M,N,K(0 < M,N,K ≤ 10000),要求出最小的瓦片数L,使L片瓦片可以拼出N种矩形,L-K片瓦片可以拼出M种矩形。

如果l小于10000,则输出l,否则输出0

样例输入:

2 3 1

样例输出:

16

样例解释:16(L)片瓦片可以拼出3种(1*16,2*8,4*4),15(L-K)片瓦片可以拼出2种(1*15,3*5)

代码如下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int findd(int num)
{
    if(num < 0)
        return -1;
    int cont = 0;
    for(int i = 1; i <= sqrt(num*1.0); i++)
    {
        if(num%i == 0)
        {
            cont++;
        }
    }
    return cont;
}
int main()
{
    int m, n, k;
    while(~scanf("%d%d%d",&m,&n,&k))
    {
        int ans = 0;
        for(int i = 1; i <= 10000; i++)
        {
            if(findd(i)==n && findd(i-k)==m)
            {
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: