首页 > 其他分享 >ZOJ 2873 Smart Sister

ZOJ 2873 Smart Sister

时间:2022-11-09 20:02:13浏览次数:41  
标签:2873 Sister his ZOJ number Kamran she report include


Smart Sister


Time Limit: 5 Seconds       Memory Limit: 32768 KB


Yesterday, Kamran was working on a report, which he must submit to his boss next Saturday. He became tired and went out of his working room to take a nap. After some minutes, her sister, Kamelia, who is a first year university student, came to the room and found the report. She thought, "How many large positive integers in a document. I hate these large numbers, they make me see nightmares! I should represent them in a more compact way". At first, she devised an ambiguous way to represent a number. She computed the product of digits of a number to find a new number and repeated this process again and again until she reached a one digit number (For example, 972 was transformed to 126 and then to 12 and finally to 2).

But she simply understood that this process is not reversible and tried to find another way (Since she loves Kamran too much, she did not want to destroy his efforts!). Suddenly, she noticed an interesting property in all the numbers of the report and called it productivity property in her mind. By her definition, a number with productivity property is a number that can be obtained by multiplying the digits of some other number (for instance, 126, 12, and 2 has productivity property, because they can be obtained from 972, 126, and 12 respectively). She thought, "Wow, I found it. If a number x in the report is the i-th number in the increasing sequence of positive integers having productivity property, I will replace it by i". She replaced all numbers of the report, put a note for Kamran describing what she did with the numbers of his report and went to her friend��s home in a blink of an eye!!!

It is not hard to imagine, how loudly Kamran screamed when he saw the report and the note from Kamelia! In addition, he wondered how she did this! He thought "Again this naughty smart sister". Now, Kamran needs your help to find his original report numbers.

Input

Input begins with a number T showing the number of test cases and then, T test cases follow. Each test case includes a positive integer i which is the number written by Kamran��s sister in the report. Please note than input includes thousands of test cases.

Output

For each test case, your program must output the original number x that was converted to the given i. Please note that it is guaranteed that the output number is less than 1018.

Sample Input

4
10
1
40
11

Sample Output

10
1
80

12

直接预处理出全部数字就好了

#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1000005;
const LL limit = 1e18;
LL f[maxn], n, T, x;
int a[5] = { 2, 3, 5, 7 };

void dfs(int x, int y, LL u)
{
if (x > 3 || u > limit) return;
if (y) f[n++] = u;
dfs(x + 1, 0, u);
dfs(x, y + 1, u * a[x]);
}

int main()
{
f[0] = n = 1;
dfs(0, 0, 1);
sort(f, f + n);
scanf("%lld", &T);
while (T--)
{
scanf("%lld", &x);
printf("%lld\n", f[x-1]);
}
return 0;
}



标签:2873,Sister,his,ZOJ,number,Kamran,she,report,include
From: https://blog.51cto.com/u_15870896/5838703

相关文章

  • ZOJ 2872 Binary Partitions
    BinaryPartitionsTimeLimit: 2Seconds     MemoryLimit: 65536KBHadilovesbinarynumbers.Sohelikestopartitioneverythingintopowersoftwo......
  • ZOJ 2132 the most frequent number
    DescriptionSeven(actuallysix)problemsmaybesomewhatfewforacontest.ButIamreallyunabletodeviseanotherproblemrelatedtoFantasyGameSeries.......
  • ZOJ 3605 Find the Marble
    DescriptionAliceandBobareplayingagame.Thisgameisplayedwithseveralidenticalpotsandonemarble.Whenthegamestarts,Aliceputsthepotsinone......
  • ZOJ 2068 Chopsticks
    DescriptionIt'sDecember2nd,Mr.L'sbirthday!HeinvitedKpeopletojoinhisbirthdayparty,andwouldliketointroducehiswayofusingchopsticks.So,he......
  • ZOJ 3911 Prime Query
    PrimeQueryTimeLimit: 1Second     MemoryLimit: 196608KBYouaregivenasimpletask.Givenasequence A[i] with NHerearetheoperations:Av......
  • ZOJ 3905 Cake
    CakeTimeLimit: 4Seconds     MemoryLimit: 65536KBAliceandBoblikeeatingcakeverymuch.Oneday,AliceandBobwenttoabakeryandboughtm......
  • [bzoj3033] 太鼓达人 (欧拉回路)
    学会了欧拉回路pwpwpwpwpwpDescription七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行。这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是......
  • BZOJ P3732 Network(Kruskal重构树)
    Network题目描述:给\(N\)个点的无向图\(\left(1\leqN\leq15000\right)\),记为:\(1\dotsN\)图中有\(M\)条边\(\left(1\leqM\leq30000\right)\),第\(i\)......
  • 树上连通有关背包:【BZOJ4182】shopping &【HDU6566】The Hanged Man
    选这两道题是因为这两道题都是树上背包,而且选的点的要求都与连通性有关,而且都是按dfs序DP来模拟不断加入物品,而且都能用树剖和点分治优化(不过优化的点一个跟子树大小有......
  • 【XSY2444】【BZOJ4042】【CERC2014】【luogu4757】Parades(树形dp+状压dp)
    题面Description从前有个A国,它有\(n\)个城市和\(n-1\)条道路。每条路连接两个城市。城市之间两两可达。每个城市与不超过10条道路相连。现在给出\(m\)条路径,要求从这些......