Given three integers n(1≤n≤1018), m(1≤m≤105), k(1≤k≤1018).
you should find a list of integer A1,A2,…,Am which
satisfies three conditions:

1. A1+A2+⋯+Am=n.

2. 1≤Ai≤k−1 for
each (1≤i≤m).

3. GCD(A1,A2,…,Am)=1.GCD
means the greatest common divisor

4. if i<j then Ai≥Aj.

As the author is too lazy to write a special judge, if there's no answer ouput "I love ACM", And if there's more than one answer, output the one has the minimum A1,
and if there still multiple answer make theA2 as
small as possible, then A3,A4…

m=1  直接 “I love ACM”

m=2

均摊 第二个给第一个不断给1

m=3

均摊 最后一个给第一个1个1

很多边界数据注意下

3 3 1

1 1 1

1 1 4

等等..

代码如下:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
long long n,m,k;
long long gcd(long long a,long long b)
{
long long r;
while(b>0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
long long A[100000+5];
void do1()
{
if(n%2==1)
{
long long p=n/2+1;
if(p<=k-1) printf("%lld %lld\n",p,p-1);
else printf("I love ACM\n");
}
else
{
int ok=1;
long long a=n/2,b=n/2;
while(a+1<=k-1&&b-1>=1)
{
a++;
b--;
if(gcd(a,b)==1)
{
ok=0;
printf("%lld %lld\n",a,b);
break;
}
}
if(ok)
printf("I love ACM\n");
}
}
void do2()
{
memset(A,0,sizeof(A));
for(int i=1;i<=m;i++)
{
A[i]=n/m;
}
for(int i=1;i<=n%m;i++)
{
A[i]++;
}
if(n%m==0&&n!=m)
{
A[1]++;A[m]--;
}
if(A[1]<=k-1&&A[m]>=1)
{
for(int i=1;i<=m;i++)
{
printf("%lld",A[i]);
if(i!=m) printf(" ");
}
printf("\n");
}
else printf("I love ACM\n");
}
int main()
{
while(cin>>n>>m>>k)
{
if(m==1&&n!=1||k==1) printf("I love ACM\n");
else if(m==1&&n==1) printf("1\n");
else
{
if(m==2) do1();
else if(m>=3) do2();
}
}
}

最新文章

  1. TeamViewer12.0.71503(远程控制软件)精简版 单文件企业版介绍
  2. java工程师 学习路线图
  3. 【Unity3D游戏开发】之利用语法糖添加自定义拓展方法(下) (十八)
  4. javaweb--下载文件列出
  5. [ CodeVS冲杯之路 ] P1053
  6. 2014第五届蓝桥杯试题C/C++程序设计B组——切面条
  7. 服务器 tfs不提供 TeamFoundation服务。基础连接已经关闭
  8. table固定前两列和最后一列,其他滑动显示
  9. java根据概率生成数字
  10. Webdriver之API详解(3)
  11. commons-lang3之StringUtils
  12. Jmeter5.1.1创建一个http请求的压力测试
  13. [20181204]低版本toad 9.6直连与ora-12505.txt
  14. jQuery EasyUI布局容器layout实例精讲
  15. try{s.send(t.hasContent&amp;&amp;t.data||null)}catch(e){if(n)throw e}}引发的惨案
  16. 纯C:AES256
  17. android 4.0 webview 无法播放视频
  18. Eclipse怎么样添加智能感知提示功能(含Windows版和Mac版)
  19. Haskell语言学习笔记(40)Arrow(1)
  20. python简单实现随机验证码

热门文章

  1. 熬之滴水穿石:Spring--精简的J2EE(5)
  2. 对Textbox的值转换为带千位符和小数的Decimal字符串
  3. 什么是目标、度量、KPI、维度和细分
  4. Java File 类的使用方法详解(转)
  5. WebConfig配置 文件加密处理
  6. HDU 2653 - Waiting ten thousand years for Love
  7. oracle使用口令文件验证和os验证
  8. Linux环境下常用的SSH命令
  9. C++有没有string转化int的函数,怎样转换
  10. sql server数据库实现保留指定位数小数的函数