B - Banana Watch

Time Limit: 1000/1000MS (Java/Others)     Memory Limit: 262144/262144KB (Java/Others)
Submit 
Status

As a famous technology company, Banana Inc. invents Banana Watch, redefining the watch.

While a normal watch has 12 indexes
and two or three moving hands, a Banana Watch has n indexes
and a moving hand.

The moving hand is at 0 initially,
and in 1st second,
it turns 1 index
clockwise; in 2nd second,
it turns 2 indexes
clockwise; ... ;

in ith second,
it turns 

i indexes
clockwise. When it moves back to 0 exactly,
one minute passes (Yes, Banana Inc. also redefines the minute).

How many seconds in the first minute?

Input

One integer n.

3≤n≤106

Sample input and outputOutput

Print the number of seconds in the first minute.

Sample Input Sample Output
3
2
5
4

Hint

If n=5,
in 1st second,
the hand moves to 1;
in 2nd second,
the hand moves to 3;
in 3rd second,
the hand moves to 1;
in 4th second,

the hand moves to 0.
So the answer for n=5 is 4.

My Solution

用sum[i]表示1~i的和,然后,从1 ~ maxn 查找。第一次出现if((sum[i] %= n) == 0) {printf("%d", i); break;}

然后考虑到数据范围。所以第一发有maxn = 2000000 + 1000,然后就过了。

假设用 1000000 + 8可能过也可能过不了。

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 2000000 + 1000;
long long sum[maxn];
int main()
{
int n;
scanf("%d", &n);
sum[0] = 0;
for(int i = 1; i < maxn; i++){
sum[i] += sum[i-1]+i;
if((sum[i] %= n) == 0) {printf("%d", i); break;}
}
return 0;
}

Thank you!

The 14th UESTC Programming Contest Final B - Banana Watch 预处理、前缀和的更多相关文章

  1. The 16th UESTC Programming Contest Final 游记

    心情不好来写博客. 为了满足ykk想要气球的愿望,NicoDafaGood.Achen和我成功去神大耍了一圈. 因为队名一开始是LargeDumpling应援会,然后队名被和谐,变成了学校的名字,顿时 ...

  2. The 15th UESTC Programming Contest Preliminary J - Jermutat1on cdoj1567

    地址:http://acm.uestc.edu.cn/#/problem/show/1567 题目: Jermutat1on Time Limit: 3000/1000MS (Java/Others) ...

  3. The 15th UESTC Programming Contest Preliminary C - C0ins cdoj1554

    地址:http://acm.uestc.edu.cn/#/problem/show/1554 题目: C0ins Time Limit: 3000/1000MS (Java/Others)     M ...

  4. The 15th UESTC Programming Contest Preliminary B - B0n0 Path cdoj1559

    地址:http://acm.uestc.edu.cn/#/problem/show/1559 题目: B0n0 Path Time Limit: 1500/500MS (Java/Others)    ...

  5. The 15th UESTC Programming Contest Preliminary K - Kidd1ng Me? cdoj1565

    地址:http://acm.uestc.edu.cn/#/problem/show/1565 题目: Kidd1ng Me? Time Limit: 3000/1000MS (Java/Others) ...

  6. The 15th UESTC Programming Contest Preliminary M - Minimum C0st cdoj1557

    地址:http://acm.uestc.edu.cn/#/problem/show/1557 题目: Minimum C0st Time Limit: 3000/1000MS (Java/Others ...

  7. 2016 China Collegiate Programming Contest Final

    2016 China Collegiate Programming Contest Final Table of Contents 2016 China Collegiate Programming ...

  8. 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定理

    2018 China Collegiate Programming Contest Final (CCPC-Final 2018)-K - Mr. Panda and Kakin-中国剩余定理+同余定 ...

  9. The 15th UESTC Programming Contest Preliminary G - GC?(X,Y) cdoj1564

    地址:http://acm.uestc.edu.cn/#/problem/show/1564 题目: G - GC?(X,Y) Time Limit: 3000/1000MS (Java/Others ...

随机推荐

  1. 国内站点经常使用的一些 CDN 静态资源公共库加速服务

    web开发人员们的福利来了..旨在为大家提供更快很多其它更好的静态资源库的CDN载入库方案! CDN公共库是指将经常使用的JS库存放在CDN节点,以方便广大开发人员直接调用. 与将JS库存放在serv ...

  2. Verilog 基础回顾 (一)

    Verilog 大小写敏感,且所有关键字都是小写 1  寄存器 register = storage,是数据存储单元的抽象,可视为能够存储数值的变量 (variable that can hold v ...

  3. IOS开发帐号与发布问题综合

    一.iOS开发:AD-HOC版应用测试方法:http://hi.baidu.com/kangle1208/item/163f39530abb4d3195eb05a7 二.plist的方式发布: 1.y ...

  4. Mybatis3.x与Spring4.x整合

    一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn archetype:create -DgroupId=me.gacl -DartifactId=spring4-myba ...

  5. Tomcat 改服务器编码(Java 修改字符串编码格式)

    对于客户端发来的汉字,我们一般需要转码: ------------------------------------------------------------------------------- ...

  6. 【apache2】apache2查看错误日志、请求日志

    1.一般存储路径在 [ /var/log/apache2/ ]下面, 2.错误日志和请求日志 必须要进行定期清理. 清理完成后,必须重启apache  [  cd /  ;  service apac ...

  7. android的NDK和java进行本地socket通信

    关于Android应用与Framework的socket通信,相信关心这个问题的朋友们已经看过<android使用socket使底层和framework通信>这篇文章,美中不足的是作者只贴 ...

  8. C# -- HttpWebRequest 和 HttpWebResponse 的使用 C#编写扫雷游戏 使用IIS调试ASP.NET网站程序 WCF入门教程 ASP.Net Core开发(踩坑)指南 ASP.Net Core Razor+AdminLTE 小试牛刀 webservice创建、部署和调用 .net接收post请求并把数据转为字典格式

    C# -- HttpWebRequest 和 HttpWebResponse 的使用 C# -- HttpWebRequest 和 HttpWebResponse 的使用 结合使用HttpWebReq ...

  9. WPF 流文档

    WPF文本显示: WPF面向的是UI展现,而文本显示无疑是UI层中的重要功能之中的一个.WPF提供了XPS (XML 文件规范) 和Flow Document (流文档) 来在不同的场景下展现或者操作 ...

  10. API 版本控制的几种方式

    个人建议:用content type,即放在Header里面!比如加一个Version:1.4.3 这篇文章写得很好,介绍了三种实现web api版本化的三种方式.我从评论里又收集到两种方式,所以一共 ...