ACM暑期集訓 同餘定理 逆元 大數取餘

2021-08-21 17:54:14 字數 1633 閱讀 4358

表面上看這道題是問a能不能整除b,實際上還是看二者取餘餘數是否為0,屬於大數取餘的範圍

a的範圍達到10的200次方,用 long long都已經不可以,需要用字串,而b可以用long long

題目:given two integers,aandb, you should check whetherais divisible bybor not. we know that an integerais divisible by an integerbif and only if there exists an integercsuch thata = b * c.

input

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

each case starts with a line containing two integersa (-10200 ≤ a ≤ 10200)andb (|b| > 0, b fits into a 32 bit signed integer). numbers will not contain leading zeroes.

output

for each case, print the case number first. then print'divisible'ifais divisible byb. otherwise print'not divisible'.

sample input

6101 101

0 67

-101 101

7678123668327637674887634 101

11010000000000000000 256

-202202202202000202202202 -101

sample output

case 1: divisible

case 2: divisible

case 3: divisible

case 4: not divisible

case 5: divisible

case 6: divisible

**:(關鍵就是那一步,研究懂就可以)

#include #include typedef long long ll;

int main()

{ int t,k=0,i;

scanf("%d",&t);

while(t--)

{ char s[1000];

k++;

long long b;

scanf("%s%lld",s,&b);

int len=strlen(s);

ll num=0;

for(i=0;i

暑假集訓(基礎數論 同餘定理)

同餘定理是數論中的重要概念。給定乙個正整數m,如果兩個整數a和b滿足 a b 能夠被m整除,即 a b m得到乙個整數,那麼就稱整數a與b對模m同餘,記作a b mod m 兩個整數a b,若它們除以整數m所得的餘數相等,則稱a與b對模m同餘或a同余於b模m。記作a b mod m 定義 設m是大於...

同模餘定理

宣告 借鑑高手!一 同餘 對於整數除以某個正整數的問題,如果只關心餘數的情況,就產生同餘的概念。定義1用給定的正整數m分別除整數a b,如果所得的餘數相等,則稱a b對模m同餘,記作a b mod m 如 56 0 mod 8 定理1整數a,b對模m同餘的充要條件是 a b能被m整除 即m a b ...

同模餘定理

同模餘定理 所謂的同餘,顧名思義,就是許多的數被乙個數 d 去除,有相同的餘數。d 數學上的稱謂為模。如 a 6,b 1,d 5,則我們說 a 和 b 是模 d 同餘的。因為他們都有相同的餘數 1 a b mod d 1 a 和 b 是模 d 同餘的.2 存在某個整數 n 使得 a b nd 3 d...