It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.
After the event, we analysed the laws of failed attacks.
It's interesting that the i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.
At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.
10 1 11 13 123 1234 12345 123456 1234567 12345678 123456789
1 12 14 125 1250 12348 123480 1234800 12348000 123480000
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> using namespace std; const int maxn=10000000000; int a[112345]; int main() { int i,j,k,e; long long x1,x2,x3,y; int top=0; for(i=0;i<30;i++) { x1=pow(2.0,i); for(j=0;j<19;j++) { x2=pow(3.0,j)*x1; if(x2>maxn) continue;//x2的值大于maxn时结束本次'; for(e=0;e<13;e++) { x3=pow(5.0,e)*x2; if(x3>maxn) continue; for(k=0;k<11;k++) { y=x3*pow(7.0,k); if(y<=maxn) a[top++]=y;//储存; } } } } sort(a,a+top); int t,p; cin>>t; while(t--) { int n; cin>>n; p=upper_bound(a,a+top,n)-a;//找第一个比n大的数; if(a[p-1]==n) p--;//找第一个不小于n的数字; cout<<a[p]<<endl; } }
*#include <iostream> #include<math.h> #include<algorithm> using namespace std; long long s[8100000],ss; int i; void f() { int a,b,c,d; for(a=0;a<30;a++) { ss=pow(2,a); if(ss/100000000000<1) for(b=0;b<19;b++) { ss=pow(2,a)*pow(3,b); if(ss/100000000000<1) for(c=0;c<16;c++) { ss=pow(2,a)*pow(3,b)*pow(5,c); if(ss/10000000000<1) for(d=0;d<12;d++) { ss=pow(2,a)*pow(3,b)*pow(5,c)*pow(7,d); if(ss/10000000000<1) s[i++]=ss; else break; } else break; } else break; } else break; } } int main() { int n; long long x; i=0; f(); sort(s,s+i); cin>>n; while(n--) { cin>>x; int p=lower_bound(s,s+i,x)-s; cout<<s[p]<<endl; } return 0; } #include <iostream> #include <cmath> #include <vector> #include <cstdlib> #include <cstdio> #include <climits> #include <ctime> #include <cstring> #include <queue> #include <stack> #include <list> #include <algorithm> #include <map> #include <set> #define LL long long #define Pr pair<int,int> #define fread(ch) freopen(ch,"r",stdin) #define fwrite(ch) freopen(ch,"w",stdout) using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1e9+7; const double eps = 1e-8; const int maxn = 6000; const LL bnd = 1123456789ll; LL lis[maxn]; int len; const int fac[4] = {2,3,5,7}; void dfs(int pos,LL v){ if(pos == 4){ lis[len++] = v; return; } do{ dfs(pos+1,v); v *= fac[pos]; }while(v <= bnd); } int main() { //fread(); //fwrite(); len = 0; dfs(0,1); sort(lis,lis+len); int T; LL n; scanf("%d",&T); while(T-- && ~scanf("%I64d",&n)){ printf("%I64d\n",*lower_bound(lis,lis+len,n)); } return 0; } #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int N=110000; int a[N]; int main(){ int t; int j=1,k=1,x=1,y=1; a[1]=1; for(int i=2;i<=5843;i++){ a[i]=min(2*a[k],min(3*a[j],min(5*a[x],7*a[y]))); if(a[i]==2*a[k])k++; if(a[i]==3*a[j])j++; if(a[i]==5*a[x])x++; if(a[i]==7*a[y])y++; } // cout<<a[5840]; // for(int i=1;i<=10;i++){ // cout<<a[i]<<endl; // } scanf("%d",&t); while(t--){ int d; scanf("%d",&d); //cout<<d; int tt=lower_bound(a+1,a+5843,d)-a; printf("%d\n",a[tt]); } return 0; } #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<climits> using namespace std; #define LL long long #define maxn 1100000 LL arr[maxn]; const LL MAX=2147483647; LL vis[4][105]; int main(){ vis[0][0] = vis[1][0] = vis[2][0] = vis[3][0] = 1; for(int i = 1;i < 33;i++) vis[0][i] = vis[0][i - 1] * 2; for(int i = 1;i < 26;i++) vis[1][i] = vis[1][i - 1] * 3; for(int i = 1;i < 19;i++) vis[2][i] = vis[2][i - 1] * 5; for(int i = 1;i < 16;i++) vis[3][i] = vis[3][i - 1] * 7; int t=0; LL temp; for(int i=0;i<33;++i){ temp = vis[0][i]; if(temp > MAX) continue; for(int j=0;j<26;++j){ temp = vis[0][i] * vis[1][j]; if(temp > MAX) continue; for(int k=0;k<19;++k){ temp = vis[0][i] * vis[1][j] * vis[2][k]; if(temp>MAX) continue; for(int s=0;s<16;++s){ temp = vis[0][i] * vis[1][j] * vis[2][k] * vis[3][s]; if(temp>MAX) continue; else arr[t++]=temp; } } } } sort(arr,arr+t); LL n,T; scanf("%I64d",&T); while(T-- && scanf("%I64d",&n)){ int pos=lower_bound(arr,arr+t,n)-arr; printf("%I64d\n",arr[pos]); } return 0; }*/
本文介绍了一种基于特定数学规则的计数游戏算法,玩家需找出不小于给定整数的最小计数二三数。计数二三数是指可以表示为2^a * 3^b * 5^c * 7^d形式的正整数,其中a、b、c、d是非负整数。文章详细展示了如何通过多种编程技巧高效求解该问题,并提供了多个实现示例。
1496

被折叠的 条评论
为什么被折叠?



