三 G - Problem G

People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that this market segment was so far underestimated and that there is lack of such games. This kind of game was thus included into the KOKODáKH. The rules follow:

Each player chooses two numbers Ai and Bi and writes them on a slip of paper. Others cannot see the numbers. In a given moment all players show their numbers to the others. The goal is to determine the sum of all expressions Ai Bi from all players including oneself and determine the remainder after division by a given number M. The winner is the one who first determines the correct result. According to the players' experience it is possible to increase the difficulty by choosing higher numbers.

You should write a program that calculates the result and is able to find out who won the game.

Input
The input consists of Z assignments. The number of them is given by the single positive integer Z appearing on the first line of input. Then the assignements follow. Each assignement begins with line containing an integer M (1 <= M <= 45000). The sum will be divided by this number. Next line contains number of players H (1 <= H <= 45000). Next exactly H lines follow. On each line, there are exactly two numbers Ai and Bi separated by space. Both numbers cannot be equal zero at the same time.
Output
For each assingnement there is the only one line of output. On this line, there is a number, the result of expression
(A1B1+A2B2+ ... +AHBH)mod M.

Sample Input
3
16
4
2 3
3 4
4 5
5 6
36123
1
2374859 3029382
17
1
3 18132
Sample Output
2
13195
13
問題鏈接:https://vjudge.net/contest/276592#problem/G
問題簡述:求(a1b1+a2b2+......+an^bn)%m
問題分析:數(shù)據(jù)過大桩匪,要用快速冪
程序說明:快速冪取余
AC通過的C++程序如下:

include<iostream>

using namespace std;
int main()
{
long long t, m,time, sum, a, b;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> m >> time;
sum = 0;
for (int j = 0; j < time; j++)
{
cin >> a >> b;
long long ans = 1;
while (b != 0)
{
if (b & 1 != 0)
{
ans=ansa%m;
}
a=a
a%m;
b >>= 1;
}
sum+=ans%m;
}
if (sum > m)
{
sum = sum % m;
}
cout << sum << endl;

    }
return 0;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末勋拟,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子提揍,更是在濱河造成了極大的恐慌溉旋,老刑警劉巖畸冲,帶你破解...
    沈念sama閱讀 222,729評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異观腊,居然都是意外死亡邑闲,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評論 3 399
  • 文/潘曉璐 我一進店門梧油,熙熙樓的掌柜王于貴愁眉苦臉地迎上來苫耸,“玉大人,你說我怎么就攤上這事儡陨⊥首樱” “怎么了量淌?”我有些...
    開封第一講書人閱讀 169,461評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長褐筛。 經(jīng)常有香客問我类少,道長,這世上最難降的妖魔是什么渔扎? 我笑而不...
    開封第一講書人閱讀 60,135評論 1 300
  • 正文 為了忘掉前任硫狞,我火速辦了婚禮,結(jié)果婚禮上晃痴,老公的妹妹穿的比我還像新娘残吩。我一直安慰自己,他們只是感情好倘核,可當(dāng)我...
    茶點故事閱讀 69,130評論 6 398
  • 文/花漫 我一把揭開白布泣侮。 她就那樣靜靜地躺著,像睡著了一般紧唱。 火紅的嫁衣襯著肌膚如雪活尊。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,736評論 1 312
  • 那天漏益,我揣著相機與錄音蛹锰,去河邊找鬼。 笑死绰疤,一個胖子當(dāng)著我的面吹牛铜犬,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播轻庆,決...
    沈念sama閱讀 41,179評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼癣猾,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了余爆?” 一聲冷哼從身側(cè)響起纷宇,我...
    開封第一講書人閱讀 40,124評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蛾方,沒想到半個月后像捶,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,657評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡转捕,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,723評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了唆垃。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片五芝。...
    茶點故事閱讀 40,872評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖辕万,靈堂內(nèi)的尸體忽然破棺而出枢步,到底是詐尸還是另有隱情沉删,我是刑警寧澤,帶...
    沈念sama閱讀 36,533評論 5 351
  • 正文 年R本政府宣布醉途,位于F島的核電站矾瑰,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏隘擎。R本人自食惡果不足惜殴穴,卻給世界環(huán)境...
    茶點故事閱讀 42,213評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望货葬。 院中可真熱鬧采幌,春花似錦、人聲如沸震桶。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蹲姐。三九已至磨取,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間柴墩,已是汗流浹背忙厌。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留拐邪,地道東北人慰毅。 一個月前我還...
    沈念sama閱讀 49,304評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像扎阶,于是被迫代替她去往敵國和親汹胃。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,876評論 2 361

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,350評論 0 10
  • 哭泣的雨 打濕街泥 泥濘了心情 勾起思緒 剪不斷的雨線 穿起記憶 看不見的雨幕 覆蓋了結(jié)局 那份情懷 縈繞著 整個...
    琢玉書生閱讀 327評論 2 20
  • 柔軟的疼痛 我要學(xué)攝影
    一一空閱讀 196評論 0 0
  • 起風(fēng)的時候 樹的旋舞 驚起鳥的歡快 急疾 遁走 穿越林間的喜悅 如絲線 串起葉的波涌 深青淺綠 杏黃香檳 美不勝收...
    SharonZhou閱讀 269評論 0 1
  • 出現(xiàn)這種情況的原因有兩種情況: 調(diào)試https安全鏈接的時候沒有安卓charles提供的證書东臀。請參考(需翻墻)進行...
    ysnows閱讀 8,118評論 3 3