LightOJ 1282 求n k的前三位和後三位

2021-09-19 11:56:43 字數 1523 閱讀 2602

you are given two integers:nandk, your task is to find the most significant three digits, and least significant three digits ofnk.

input

input starts with an integert (≤ 1000), denoting the number of test cases.

each case starts with a line containing two integers:n (2 ≤ n < 231)andk (1 ≤ k ≤ 107).

output

for each case, print the case number and the three leading digits (most significant) and three trailing digits (least significant). you can assume that the input is given such thatnkcontains at least six digits.

sample input

5123456 1

123456 2

2 31

2 32

29 8751919

sample output

case 1: 123 456

case 2: 152 936

case 3: 214 648

case 4: 429 296

case 5: 665 669

後3位好求,模一下就行了,關鍵是前3位。

我們可以這樣考慮,對於任何乙個數n,都有

我們知道,n的數字為

對於

#include #include #include #include #include #include #include #include #include #define eps 1e-8

#define lson l,mid,pos<<1

#define rson mid+1,r,pos<<1|1

typedef long long ll;

const double pi = acos(-1.0);

const int maxn = 1e6;

const int inf = 1e9;

const ll linf = 0x3f3f3f3f3f3f3f3f;

using namespace std;

int qsm(int a, int b, int mod)

return ans;

}int main()

return 0;

}

求A B的最後三位數

求a b的最後三位數 首先需要知道乙個公式 a b c a c b c c為什麼需要這個公式?a b的結果可能出現溢位,所以取模之後就不會了 快速冪解法 2.1 首先將冪指數用二進位制表示,例如 313 31101 38 34 31。所以最後的結果就是將二 進製中為1的係數冪乘起來即可 2.2 第二...

練習,求滿足條件的三位數

特殊三位數 請輸出滿足條件n a b c 的所有三位數 n,其中,a b c分別是 n的百 十 個位數。要求用自定義函式實現求階乘。include using namespace std 自定義函式的原型 即函式宣告 int fac int int main int s,a,b,c,x 100 wh...

第3關 求三位數各位數字的和

任務描述 本關任務 編寫程式,從鍵盤輸入乙個三位數整數,計算並輸出乙個三位整數中各位上的數字之和。如 369上各位數字之和為3 6 9 18 任務分析 三位數求和需要先計算出三位數的百位 十位和個位,然後才能計算百位 十位和個位的和。可以利用兩個整數相除得到的整數是不包含餘數的商來求得數字的百位 十...