你的位置:首页 > 软件开发 > Java > 85:有趣的数

85:有趣的数

发布时间:2017-12-05 05:00:05
描述把分数按下面的办法排成一个数表。1/1 1/2 1/3 1/4.....2/1 2/2 2/3....3/1 3/2 ....4/1..............我们以z字型方法给上表的每项编号。特定方法:第一项是1/1,然后是1/2、2/1、3/1、2/2、1/3、1/4、2 ...

描述

把分数按下面的办法排成一个数表。

1/1 1/2 1/3 1/4.....

2/1 2/2 2/3....

3/1 3/2 ....

4/1.....
.........

我们以z字型方法给上表的每项编号。特定方法:第一项是1/1,然后是1/2、2/1、3/1、2/2、1/3、1/4、2/3……。编程输入项号N(1<=N<=100000),输出表中第N项。

 
输入
第一行有一个整数m(0<m<=10),表示有m组测试数据;
随后有m行,每行有一个整数N;
输出
输出表中第N项
样例输入
4314712345
样例输出
2/12/41/459/99

 1 package com.nanyang.oj; 2  3 import java.util.Scanner; 4  5 public class acm85 { 6  public static void main(String[] args){ 7   Scanner scan=new Scanner(System.in); 8    9   int time=scan.nextInt();10   11   while(time>0){12    13    int num=scan.nextInt();14    int temp=(int)Math.sqrt(2*num);15    16    if(num==1){17     System.out.printf("1/1\n");18     time--;19     continue;20    }21    22    for(int i=temp;i>0;i--){23     if(i*(i+1)<num*2){24      temp=i;25      break;26     }27    }28    29    if(temp%2==0){30     int i=(1+temp)*temp/2;31     num=num-i;32     System.out.printf("%d/%d\n",(temp+1)-num+1,num);33     34    }else{35     int i=(1+temp)*temp/2;36     num=num-i;37     System.out.printf("%d/%d\n",num,(temp+1)-num+1);38    }39    40    time--;41   }42  }43 }

 






 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:85:有趣的数

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录