http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2313

要想满足要求 k 必须和 n 是互质的

当球第一次回到起点是  球走过的路程是 k和n 的最小公倍数

如果 k 和 n 互质 那么球正好传递了 n 次 正好每个人都传了一次

如果 k 和 n 不互质 就不能满足条件了

从 n/2 开始搜 很快就可以搜到和 n 互质的数

代码:

import java.math.BigInteger;
import java.util.Scanner;public class Main {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubScanner in = new Scanner(System.in);int T;T = in.nextInt();while ((T--) > 0) {BigInteger a = in.nextBigInteger();BigInteger b = a.divide(BigInteger.ONE.add(BigInteger.ONE));while (b.compareTo(BigInteger.ZERO) == 1) {if (a.gcd(b).compareTo(BigInteger.ONE) == 0) {break;}b = b.subtract(BigInteger.ONE);}System.out.println(b);if (T > 0) {System.out.println();}}}}

  

转载于:https://www.cnblogs.com/liulangye/archive/2013/04/20/3032280.html

zoj 2313 Chinese Girls' Amusement相关推荐

  1. zoj 2313 Chinese Girls' Amusement(2-A)

    题目地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 这题的理论就是当且仅当(a,m)=1  时  a*k+b (1 ...

  2. ZOJ2313 Chinese Girls' Amusement(大数运算,找规律)

    题目: Chinese Girls' Amusement Time Limit: 2 Seconds       Memory Limit: 65536 KB You must have heard ...

  3. ACdream 1210 Chinese Girls' Amusement

    题目链接:http://115.28.76.232/problem?pid=1210 Problem Description You must have heard that the Chinese ...

  4. zoj 1137 || 1466 Girls and Boys

    二分图的最大独立集=顶点数-二分图的最大匹配数 二分图的最小顶点覆盖=二分图的最大匹配数 二分图的最小路径覆盖=顶点数-二分图的最大匹配数 zoj上居然没写数据范围...poj写了. 这题是求最大独立 ...

  5. iis里面的mime没有php扩展,IIS - 无后缀(无扩展名)的MIME类型配置

    javascript call与apply关键字的作用 apply接受两个参数.第一个参数指定函数体内this对象的指向,第二个参数为一个带下标的集合. call则是apply的语法糖,如果参数数量固 ...

  6. 史上最全的SGU题目分类

    由于SGU上神题遍地,特列此表,便于训练时分类训练. 101 Domino 欧拉路 102 Coprime 枚举/数学方法 103 Traffic Lights 最短路 104 Little Shop ...

  7. 运维自动oncall_oncall是软件工程的50岁

    运维自动oncall I am not going to lie; software engineers have a pretty good life. We can come into the o ...

  8. 每日英语:Why is Ye Shiwen’s Swim “Disturbing”?

    American swim coach John Leonard stirred the controversy over Ye Shiwen's incredible 400 IM describi ...

  9. BERT-MRC论文笔记

    1.NER任务概述 ner(named entity recognization),命名实体识别旨在提取句子中预先定义的不同类型的实体,如person,location,organization等等. ...

最新文章

  1. ubuntu linux的特点,16个新特性,让你爱上Ubuntu 20.04,
  2. python处理完数据导入数据库_python操作数据库之批量导入
  3. php mysql 导出到excel,php mysql数据导出到excel文件
  4. oracle 12创建一个表,oracle 12 c 创建表空间,用户名,及表
  5. 一年工作经验的java面试题
  6. PMP第六版十五至尊图记忆方法
  7. IT行业毕业生投简历或面试技巧
  8. 正交性原理与维纳霍夫(正则)方程
  9. 什么是serialVersionUID?serialVersionUID详解
  10. 无法复制到远程计算机,远程桌面无法复制粘贴【解答思路】
  11. 在c语言中把x和y互换怎么编译,已知int x=10,y=12;编程将x和y的值相互交换
  12. 怎么将服务器加入系统白名单,服务器怎么添加白名单
  13. 特效制作软件AE(After Effects)插件安装
  14. endcap和welltap_ICC布局规划
  15. 027-Mac触摸板实现窗口移动
  16. Nmap常用扫描命令
  17. 虚拟化服务器里的cpu是什么型号的,VMware虚拟化CPU型号不一样,在集群中如何进行VMotion?...
  18. 计算机病毒的关键技术,计算机病毒实验系统关键技术研究与实现
  19. 创建一个包含1-10的立方的列表
  20. 车载调频广播电台移动发射系统应用

热门文章

  1. Flutter 日期选择器与时间选择器
  2. Leetcode-5199 Smallest String With Swaps(交换字符串中的元素)
  3. 使用Maven开发用户模块的CRUD(增删改查)
  4. JavaJDK8新特性相关知识整理
  5. Flask 提取数据库中的数据
  6. EffectiveJava读书笔记--01继承的使用注意
  7. 《Thinking in java》 读了个开头
  8. javascript高级知识点——继承
  9. 内置模块/核心模块 (自带的)---path模块
  10. 第六章:react-router4