以下轉自:http://hi.baidu.com/aekdycoin/blog/item/b317ca18bb24334942a9ad55.html【普通Baby Step Giant Step】【問題模型】求解A^x = B (mod C) 中 0 <= x < C 的解,C 為素數【思路】我們可以做一個等價x = i * m + j ( 0 <= i < m, 0 <=j < m) m = Ceil ( sqrt( C)
problem 1If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below
/* * pku1811.c * * Created on: 2011-8-1 * Author: 王竹*/#include<stdio.h>#include<stdlib.h>#define LL long longLL pmin;LL modular_multi(LL a, LL b, LL c) { LL ret; ret = 0, a %= c;while (b) {if (b & 1) { ret +=
題意:給你n個骰子,擺成一個塔,且相鄰的骰子的接觸的面的數字不同。而你看到的只有頂部和某兩側,現在給你的就頂部和某兩側的數字,請問,能否唯一判定所有面的數字。解法:既然要唯一,且頂部的數(假設為z)確定了,那麼要不能唯一判定所有面的數字,那下面的某一個或幾個骰子的側面的數是z或7-z,如此,即可解題,代碼如下: import java.io.BufferedInputStream;import java.util.Scanner;public class Main { public
/* * hdu1796.c * * Created on: 2011-10-3 * Author: bjfuwangzhu*/#include<stdio.h>#define LL long long#define nmax 11int num[nmax], nlen;LL res;int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}void dfs(int start, int c, int lcm,
What do I turn?很簡單,運用叉積即可得到答案。package com.wangzhu.codeforces;//What do I turn?import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.Scanner;public class Round140Div2 { public
狀態轉移方程為:num[n][k]=num[n-1][k-1]+num[n-k][k]表示n個Apple分給k個People,1).若k個人不能獲得一樣的,則為了滿足題意,需要將最後一個人先分1個,再將剩餘n-1的分給k-1個人;2).若能,則就變成了將n-k個Apple分給k個People的子過程。/* * soj3291.c * * Created on: 2011-10-10 * Author: