[蓝桥杯2018初赛]第几个幸运数
题目描述
到x星球旅行的游客都被发给一个整数,作为游客编号。
x星的国王有个怪癖,他只喜欢数字3,5和7。
国王规定,游客的编号如果只含有因子:3,5,7,就可以获得一份奖品。
前10个幸运数字是:3 5 7 9 15 21 25 27 35 45,因而第11个幸运数字是:49
小明领到了一个幸运数字 59084709587505。
去领奖的时候,人家要求他准确说出这是第几个幸运数字,否则领不到奖品。
请你帮小明计算一下,59084709587505是第几个幸运数字。
输出
输出一个整数表示答案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N=1e6+5; priority_queue<ll,vector<ll>,greater<ll> > pq; map<ll,int> mp; int a[3]={3,5,7}; int main (){ pq.push(1); ll ans=0; while(1){ ll x=pq.top(); pq.pop(); if(x==59084709587505){ printf("%lld\n",ans); break; } for(int i=0;i<3;i++){ ll temp=x*a[i]; if(mp[temp]==0){ mp[temp]=1; pq.push(temp); } } ans++; } return 0; }
|
[蓝桥杯2018初赛]哪天返回
题目描述
小明被不明势力劫持。后莫名其妙被扔到x星站再无问津。
小明得知每天都有飞船飞往地球,但需要108元的船票,而他却身无分文。
他决定在x星战打工。好心的老板答应包食宿,第1天给他1元钱。
并且,以后的每一天都比前一天多2元钱,直到他有足够的钱买票。
请计算一下,小明在第几天就能凑够108元,返回地球。
输出
输出一个整数表示答案
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N=1e6+5;
int a; int tot;
int main (){ a=1; int i=1; for(;tot<108;i++){ tot+=a; a+=2; } cout<<i-1<<endl; }
|