【问题标题】:Exception in thread "main" java.util.NoSuchElementException Runtime error getting proper output线程“main”中的异常 java.util.NoSuchElementException 运行时错误得到正确的输出
【发布时间】:2016-01-09 00:16:56
【问题描述】:

给定一个数 N,求所有乘积 x*y 的总和,使得 N/x = y(整数除法)。 由于总和可能非常大,请输出此模 1000000007。 输入

输入文件的第一行包含一个整数 T,即要遵循的测试用例数。接下来的 T 行中的每一行都包含一个整数 N。 输出

输出包含对应测试用例答案的 T 行。 `

private static Scanner sc;
public static void main(String [] args ){

    sc = new Scanner(System.in);long k;int s;
    int t = sc.nextInt(); 
    while(t>0){
        k=0;
     long n = sc.nextInt();
     for(int i=1;i<=n;i++){

             k=k+(n/i)*i;



     }



     s=(int) (k%1000000007);
     System.out.println(s);
}t--;
}

【问题讨论】:

    标签: multithreading exception main nosuchelementexception


    【解决方案1】:

    在执行上述程序时,我没有遇到任何此类异常。但是您应该将 t-- 放在 while 循环中。否则它将无限运行。

    【讨论】:

      猜你喜欢
      • 2015-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      相关资源
      最近更新 更多