生活随笔
收集整理的這篇文章主要介紹了
数字_JAVA
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Description
定義f(x) = {比x小,不可以被x整除并且不和x互質(zhì)的數(shù)的個數(shù)}(x為正整數(shù))。
當(dāng)f(x) 是奇數(shù)的時候我們稱x為“奇真數(shù)”。
給出兩個數(shù)x,y求區(qū)間[x,y]內(nèi)的“奇真數(shù)”的個數(shù)。
Input
第一行輸入一個數(shù)N代表測試數(shù)據(jù)個數(shù)(N<=20)。接下來N行每行兩個正整數(shù)x , y ( 0 < x <= y < 2^31)。
Output
對于每個測試數(shù)據(jù)輸出“奇真數(shù)”的個數(shù),每行輸出一個結(jié)果。
Sample
Input
2
1 1
1 10
Output
0
4
Hint
中國海洋大學(xué)第三屆“朗訊杯”編程比賽高級組試題
詳解:http://blog.csdn.net/tclh123/article/details/7970545
import java
.util
.*
;class F {long a
;public F
(long a
) {this.a
= a
;}public long cal() {if(a
<= 2)return 0;if((long)Math
.sqrt(a
) % 2 == 1)return a
/ 2 - 1;elsereturn a
/ 2 - 2;}
}
public class Main {public static void main(String
[] args
) {Scanner reader
= new Scanner(System
.in
);long a
, b
, t
;t
= reader
.nextLong();while(t
-- > 0) {a
= reader
.nextLong();b
= reader
.nextLong();F fa
= new F(a
- 1);F fb
= new F(b
);long sum
= fb
.cal() - fa
.cal();System
.out
.println(sum
);}reader
.close();}}
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的数字_JAVA的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。