java中求第m小光棍数_OJ水题-----有趣的数

描述:

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

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

输出:输出表中第N项

输入数据:

4

3

14

7

12345

输出数据:

2/1

2/4

1/4

59/99

/***************************************************************************/

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a = sc.nextInt();

for (int j = 0; j 

int m = sc.nextInt();

int i;

for (i = 1; m - i > 0; i++) {

m = m - i;

}

if (i % 2 == 1) {

System.out.println(i + 1 - m + "/" + m);

} else {

System.out.println(m + "/" + (i + 1 - m));

}

}

}

}

.....谁来给我讲一下...14为什么是2/4..

这是我原代码:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a = sc.nextInt();

for (int j = 0; j 

int m = sc.nextInt();

int x = 1;

int y = 1;

for (int i = 1; i 

if (y == 1) {

y = x + 1;

x = 1;

} else {

y--;

x++;

}

}

System.out.println(x + "/" + y);

}

}

}

我自己手工找也是4/2 ... 为啥测试上就说2/4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值