URAL 1157. Young Tiler (数学啊 )

题目链接:?space=1&num=1157

1157. Young Tiler

Time limit: 1.0 secondMemory 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 numbersM,NandK. You should find the smallest numberL, such as you can formNdifferent rectangles using allLtiles, and formMrectangles usingLKtiles.

Input

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

Output

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

Sample

inputoutput

2 3 116

题意:

一个年轻的瓦工,用很多瓦片拼矩形,给出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;}

天不负;卧薪尝胆,三千越甲可吞吴。

URAL 1157. Young Tiler (数学啊 )

相关文章:

你感兴趣的文章:

标签云: