Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5917 | Accepted: 2692 |
Description
Input
Output
Sample Input
7 13 19 100
Sample Output
26590291
Source
#include<iostream> #include<cstdlib> #include<stdio.h> #include<algorithm> #define ll __int64 using namespace std; ll num[100010]; ll min(ll a,ll b,ll c) { ll x=a<b?a:b; x=x<c?x:c; return x; } int main() { ll p[3],cnt; while(scanf("%I64d%I64d%I64d%I64d",&p[0],&p[1],&p[2],&cnt)!=EOF) { num[1]=1; int i=1; int y1=1,y2=1,y3=1; while(i<=cnt+1) { num[++i]=min(p[0]*num[y1],p[1]*num[y2],p[2]*num[y3]); if(num[i]==p[0]*num[y1]) y1++; if(num[i]==p[1]*num[y2]) y2++; if(num[i]==p[2]*num[y3]) y3++; } cout<<num[cnt+1]<<endl; } }