我是个菜鸡
黑心啤酒厂
Time limit per test: 2.0 seconds
Memory limit: 256 megabytes
黑心啤酒厂为了让大家买啤酒,会把一瓶酒设计成恰好能倒七杯。由于聚会时经常会有大家一起干杯这样的事情,干杯之前又要给每个人都倒满,所以来两个人的时候,干完三轮,恰好多一杯;三个人的时候,干完两轮,恰好多一杯;四个人的时候会多三杯。在上述情况下,为了践行不浪费的原则,就会多买一瓶啤酒,再干一轮。当然多买的啤酒可能又有多了……然后循环往复,喝了好多好多。直到啤酒刚刚好喝完为止。
现在啤酒厂把酒瓶设计成刚好能倒 x 杯,请依次求出有 2 人、3 人,一直到 n 人参加聚会时,啤酒厂各能卖出多少瓶啤酒。
Input
输入只有一行,两个整数 x,n (1≤x≤109,2≤n≤105)。
Output
输出 n−1 行,分别表示 2,3,…,n 人参加聚会时,能卖出的啤酒瓶数。
Examples
input
7 5
output
2
3
4
5
一开始的想法太简单了GG
#include<iostream>
using namespace std;
int main()
{
int peer=0,people=0;
cin>>peer>>people;
for(int people_i=2;people_i<=people;people_i++)
{
int peer_j=1;
while(((peer*peer_j)%people_i)!=0)
{
++peer_j;
}
if(((peer*peer_j)%people_i)==0)
cout<<peer_j<<endl;
}
return 0;
}
后来时间超了,才反应过来应该是用最大公约数
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int main()
{
int peer=0,people=0,temp=0;
cin>>peer>>people;
for(int people_i=2;people_i<=people;people_i++)
{
temp=gcd(peer,people_i);
temp=people_i/temp;
cout<<temp<<endl;
}
return 0;
}