HDU 3199Hamming Problem
来源:互联网 发布:金牛考勤软件数据库 编辑:程序博客网 时间:2024/05/21 15:43
Hamming Problem
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
For each three prime numbers p1, p2 and p3, let's define Hamming sequence Hi(p1, p2, p3), i=1, ... as containing in increasing order all the natural numbers whose only prime divisors are p1, p2 or p3.
For example, H(2, 3, 5) = 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, ...
So H5(2, 3, 5)=6.
For example, H(2, 3, 5) = 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, ...
So H5(2, 3, 5)=6.
Input
In the single line of input file there are space-separated integers p1 p2 p3 i.
Output
The output file must contain the single integer - Hi(p1, p2, p3). All numbers in input and output are less than 10^18.
Sample Input
7 13 19 100
Sample Output
26590291
#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>using namespace std;typedef long long ll;ll num[10000];int main(){ll p1, p2, p3, n;while(~scanf("%I64d%I64d%I64d%i64d", &p1, &p2, &p3, &n)){memset(num, 0, sizeof(num));num[0] = 1;ll t1, t2, t3;ll r1, r2, r3;t1 = t2 = t3 = 0;for(int i = 1; i <= n; ++i){r1 = num[t1] * p1;r2 = num[t2] * p2;r3 = num[t3] * p3;ll minn = min(r1, min(r2, r3));if(minn == r1) ++t1;if(minn == r2) ++t2;if(minn == r3) ++t3;num[i] = minn;}cout << num[n] << endl;}return 0;}
看着给出的数据范围很大,其实 i 的范围在10000 就能过。
刚开始没有思路,看了别人的代码才恍然大悟。
0 0
- hdu 3199 Hamming Problem
- HDU 3199Hamming Problem
- hdu 3199 Hamming Problem
- 【HDU 3199】【水题】Hamming Problem
- Hamming Problem(hdu 3199)
- HDU 3199 Hamming Problem 丑数
- 3199 Hamming Problem
- POJ 2545 && HDU 3199 Hamming Problem(数论)
- Hamming problem
- POJ 2545 Hamming Problem
- poj 2545 Hamming Problem
- poj2545 Hamming Problem----暴力
- POJ2545--Hamming Problem
- poj 2545 Hamming Problem
- HDU3199 Hamming Problem 【数论】
- UVA729The Hamming Distance Problem
- TOJ 1753.Hamming Problem
- 729--The Hamming Distance Problem
- iOS架构谈
- Java片段 Java中Double和Long互相转换
- /usr/bin/ld:cannot find -lIN
- HTML常用标签
- uva10069(DP + 高精度运算)
- HDU 3199Hamming Problem
- Window和DecorView
- 堆 栈
- vim ctags使用方法
- Java字符串的比较是否相同
- Vmware-NAT网络模式介绍及理解
- svn服务器搭建和使用:Custom action GenerateSSLKey failed: Command terminated with non-zero exit code
- 重启PHP
- [从头学声学] 第216节 九音真经(上)