牛客網NOIP賽前集訓營-普及組
阿新 • • 發佈:2018-09-16
cst itl long long 這樣的 -i scanner def 描述 --
保證輸入的a和b在long long範圍之內,即滿足
-9223372036854775808 <= a, b <= 9223372036854775807
計算a+b的值,即這兩個數字的和。
如果a+b在long long範圍之內,即滿足
-9223372036854775808 <= a + b <= 9223372036854775807
那麽輸出一行一個整數表示a+b的結果。
如果a+b不在long long範圍之內,即越界了,那麽輸出"hello, %lld\n",包含引號。
具體可以參見樣例。
第二場:
A-你好誒加幣
題目描述
牛牛剛學習了輸入輸出,他遇到了一道這樣的題目。 輸入2個整數a和b保證輸入的a和b在long long範圍之內,即滿足
-9223372036854775808 <= a, b <= 9223372036854775807
計算a+b的值,即這兩個數字的和。
如果a+b在long long範圍之內,即滿足
-9223372036854775808 <= a + b <= 9223372036854775807
那麽輸出一行一個整數表示a+b的結果。
如果a+b不在long long範圍之內,即越界了,那麽輸出"hello, %lld\n",包含引號。
具體可以參見樣例。
輸入描述:
輸入只有一行,包含用空格分開的兩個整數,表示a和b。
輸出描述:
如果a+b在long long範圍之內,輸出一行一個整數,表示a+b的結果;否則輸出"hello, %lld\n",包含引號。示例1
輸入
-9223372036854775808 9223372036854775807
輸出
-1示例2
輸入
9223372036854775807 1
輸出
"hello, %lld\n"
備註:
正確計算a+b可以得到50分
正確輸出"hello, %lld\n"也可以得到50分
解題思路:java大數簡單判斷即可。
AC代碼:
1 import java.util.Scanner;2 import java.math.BigInteger; 3 public class Main { 4 public static void main(String[] args) { 5 Scanner scan = new Scanner(System.in); 6 BigInteger c = new BigInteger("9223372036854775807"); 7 BigInteger d = new BigInteger("-9223372036854775808"); 8 while(scan.hasNext()){9 BigInteger a = scan.nextBigInteger(); 10 BigInteger b = scan.nextBigInteger(); 11 a = a.add(b); 12 if(a.compareTo(d)==-1||a.compareTo(c)==1) 13 System.out.println("\"hello, %lld\\n\""); 14 else System.out.println(a); 15 } 16 } 17 }
B-最後一次
題目描述
牛牛最近學習了質數的概念。 質數指在大於1的自然數中,除了1和它本身以外不再有其他因數。 輸入一個n,輸出小於等於n最大的質數。輸入描述:
輸入一個整數n
輸出描述:
輸出小於等於n的最大的質數示例1
輸入
2
輸出
2示例2
輸入
100
輸出
97
備註:
對於所有數據: 2 <= n <= 1000000000000
30分: n <= 100000
70分: n <= 1000000000
解題思路:簡單暴力一下即可。
AC代碼:
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<string.h> 5 using namespace std; 6 typedef long long LL;LL n; 7 bool is_prime(LL n){ 8 for(LL i=2;i*i<=n;++i) 9 if(n%i==0)return false; 10 return true; 11 } 12 int main(){ 13 while(~scanf("%lld",&n)){ 14 for(LL i=n;i>1;--i) 15 if(is_prime(i)){printf("%lld\n",i);break;} 16 } 17 return 0; 18 }
牛客網NOIP賽前集訓營-普及組