ACM编程题求助~

来源:百度知道 编辑:UC知道 时间:2024/05/22 12:26:47
题目:The N (1 <= N <= 50,000) cows, conveniently numbered 1..N, are trying to learn some encryption algorithms. After studying a few examples, they have decided to make one of their own! However, they are not very experienced at this, so their algorithm is very simple: Each cow i is given a starting number C_i (0 <= C_i < 90,000,000),and then all the cows perform the following process in parallel:
* First, each cow finds the sum of the numbers of the other N-1 cows. * After all cows are finished, each cow replaces her number with the sum she computed. To avoid very large numbers, the cows will keep track of their numbers modulo 98,765,431.
"Your algorithm is too easy to break! You should repeat it T(1 <= T <= 1,414,213,562) times instead."
1.Time Limit, Memory Limit *Time Limit: 1000MS *Memory Limit: 30000KB
2.Input * Line 1: Two space-separated integers: N and T *Lines 2..N+1: Line i+1 contains a single i

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

typedef _int64 LLN;
const double pi = 2.0 * acos(0.0);
const double eps = 1.0e-9;
const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
const int dr6[] = {1, 1, 0, -1, -1, 0}, dc6[] = {0, 1, 1, 0, -1, -1};
const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1}, dc8[] = {0, 1, 1, 1, 0, -1, -1, -1};

const int M = 98765431;

LLN pwr(LLN x, LLN p)
{
LLN t = 1 % M;
while (p >