poj 3307 Smart Sister(数论 打表)
2015-09-11 22:24
441 查看
题目:http://poj.org/problem?id=3307
Smart Sister
Description
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 ith number in the increasing sequence of positive integers having productivity property, I will replace it byi". 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 giveni.
Please note that it is guaranteed that the output number is less than 1018.
Sample Input
Sample Output
具体分析见下:
Smart Sister
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 2248 | Accepted: 924 |
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 ith number in the increasing sequence of positive integers having productivity property, I will replace it byi". 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 giveni.
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
具体分析见下:
/* 问题本质就是给出i,求出第i个数。在1--10中素因子有2 3 5 7.用他们来研究数字的增长即可 */ #include <iostream> #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; const LL maxn=1e18; LL allmin(LL a,LL b,LL c,LL d){ return min(min(a,b),min(c,d)); } LL a[70005],top=0; int main() { //freopen("cin.txt","r",stdin); LL p2,p3,p5,p7,q=1; a[++top]=1; p2=p3=p5=p7=1; while(q<maxn&&q>0){ q=allmin(a[p2]*2,a[p3]*3,a[p5]*5,a[p7]*7); a[++top]=q; if(q==a[p2]*2) p2++; if(q==a[p3]*3) p3++; //不是else if,因为有可能多个数字相同 if(q==a[p5]*5) p5++; if(q==a[p7]*7) p7++; } //cout<<a[top-1]<<endl; LL ca,i; cin>>ca; while(ca--){ scanf("%lld",&i); printf("%lld\n",a[i]); } return 0; }
相关文章推荐
- App整体颜色风格
- 门户APP开发,企业APP定制,商务APP营销,商城APP定做。顶级工程师为您私人订制
- 黑马程序员——java基础知识篇——>循环语句
- 理解inode
- 印尼用户app使用特点
- 移动app测试中的主要问题
- 实现strlen,strcpy,strcat,strcmp同功能的函数stringLength,stringCopy,stringCatch,stringCompare
- js的轮播效果
- JDK配置环境变量方法
- android studio 使用aar资源包
- html cheatsheet
- Poj 1258 Agri-Net(最小生成树 kruskal)
- java设计模式第6弹--单例模式
- 编译hadoop的eclipse插件hadoop-eclipse-plugin-1.2.1.jar
- Java接口和抽象类的区别
- NSOperationQueue、NSOperation理解
- Scala 深入浅出实战经典 第93讲:Akka第一个案例动手实战开发消息实体类
- PAT 1098. Insertion or Heap Sort (25)
- iOS 计算文字的高度
- 使用dup2重定向了标准输出后,使用什么方法恢复对终端的输出?? http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=359433&page=