日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

HOJ 1991 Happy 2005 HOJ 2635 Weights 快速幂

發布時間:2025/7/14 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HOJ 1991 Happy 2005 HOJ 2635 Weights 快速幂 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://acm.hit.edu.cn/hoj/problem/view?id=1991

HOJ 1991 Happy 2005

My Tags
矩陣快速冪???(Edit)
?Source?:?SCU Programming Contest 2005 Preliminary
?Time limit?: 1 sec?Memory limit?: 32 M

Submitted?: 344,?Accepted?: 223

Consider a positive integer X, and let S be the sum of all positive integer divisors of 2005X. Your job is to determine S modulo 29 (the rest of the division of 29).

Take X = 1 for example. The positive integer divisor of 20051?are 1 5 401 2005. Therefore S = 2412, and S modulo 29 is equal to 5.

Input

The input consists of several test cases. Each test case contains a line with the integer X(1 <= X <= 10000000).

A test case of X = 0 indicates the end of input, and should not be processed.

Output

For each test case, in a separate line, please output the result of S modulo 29.

Sample Input

1 10000 0

Sample Output

5 2

題目:
給出n,問2005^n的各個因子數之和對29取模

分析:
2005 = 5*401,我們可以對于401進行分類:
401^0 : 1 5 5^2 ... 5^n
401^1 : 401 401*5 401*5^2 ... 401*5^n
.
.
.
401^n : 401^n 401^n*5 401^n*5^2 ... 401^n*5^n
由此我們可以發現,問題可以轉換為
(1+401+401^2+...401^n)*(1+5+5^2+...+5^n)%29

方法一:
二分再二分。首先,a^n用一次二分,求和的時候再用一次二分。
a^n二分的時候就是快速冪。
求和二分:
A+A^2+A...+A^(2k+1)= A+A^2+...+A^k+A^(k+1)+A^(k+1)*(A+A^2+...+A^k).
A+A^2+...+A^2k = A+A^2+...+A^k+A^k*(A+A^2+...+A^k).
方法二:
構造矩陣matrix如下:
A 1
0 1
我們發現matrix^(n+1)項的時候,第一行第二列就是問題所求
所以在求A+A^2+A^3+...+A^k % 29的時候,我們可以直接轉化為對矩陣進行
快速冪取模。
我下面的代碼為構造矩陣求解。。。

#include <cstdio> #include <cstring> #include <iostream>using namespace std;typedef long long ll;#define debug puts("here");const int X = 3; const int MOD = 29;struct Matrix{ll a[X][X];int n;int mod;Matrix(){}Matrix(int _n,int _mod):n(_n),mod(_mod){memset(a,0,sizeof(a));}void setE(){memset(a,0,sizeof(a));for(int i=1;i<=n;i++)a[i][i] = 1;}Matrix operator * (Matrix p){Matrix c(n,mod);for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=1;k<=n;k++){c.a[i][j] += a[i][k]*p.a[k][j];c.a[i][j] %= mod;}return c;}Matrix pw(int exp){Matrix cur = *this;Matrix c(n,MOD);c.setE();while(exp>0){if(exp&1)c = c*cur;cur = cur*cur;exp = exp>>1;}return c;}void di(){for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)cout<<a[i][j]<<" ";cout<<endl;}}void init(int x){a[1][2] = a[2][2] = 1;a[2][1] = 0;a[1][1] = x;} }matrix;int main(){#ifndef ONLINE_JUDGEfreopen("sum.in","r",stdin); #endifll n;while(cin>>n,n){Matrix a = Matrix(2,MOD);a.init(5);a = a.pw(n+1);ll ans = a.a[1][2]%MOD;a.init(401);a = a.pw(n+1);ans = ans*a.a[1][2]%MOD;cout<<ans<<endl;}return 0; }

  

?

Weights

My Tags
??(Edit)
?Source?:?mostleg
?Time limit?: 1 sec?Memory limit?: 64 M

Submitted?: 276,?Accepted?: 103

Usually, given a balance and a group of weights (weight means poise here, and somewhere else in this problem), you will put some weights in the right plate of the balance, and add something in the left plate to make it balance.

This time you can use the balance as a different way, however, in which you can put the weights either in the left or right plate. As a result, the number of weights that can be denoted become far more than before.

Here is your task: Design the group of weights so that most consecutive integers from 1 (Unit: gram) can be denoted. Notice that every weight must be an integer (Unit: gram).

Input

The input consists of multiple test cases. In each test case, There is only an integer,?n, (1<=n<=10^9), which is the number of weights.

Output

Normally, the result should be the maximum in the consecutive integer sequence that can be denoted, but it may be very large. So you need only output the result of the maximum value mod 9999997 instead. For every case, you should output only one integer.

Sample input

1 2 1000000

Sample output

1 4 4328126

題解:同上題。。。求的是1+3^1+...+3^(n-1)
代碼略。。。

轉載于:https://www.cnblogs.com/yejinru/archive/2013/01/18/2866065.html

總結

以上是生活随笔為你收集整理的HOJ 1991 Happy 2005 HOJ 2635 Weights 快速幂的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧洲精品久久久久毛片完整版 | 国产毛片a级| 亚洲女优在线观看 | 一区精品在线 | 色婷婷18 | 97在线看| 日啪 | 国产精品久久久影院 | 亚洲AV成人无码网站天堂久久 | 蜜桃av免费看 | 欧美激情在线播放 | av在线高清观看 | 日韩欧美网站 | 久久国产精品无码一区二区 | 国产精品无码网站 | 拍真实国产伦偷精品 | 天天操天天干天天爱 | 日韩三级在线免费观看 | 激情小说激情视频 | 精品少妇无码av无码专区 | 奇米精品一区二区三区在线观看一 | 日本一级做a爱片 | 久久久精品久久久久 | 看一级黄色 | 人妻互换一二三区激情视频 | 日韩精品电影一区 | 美女张开腿流出白浆 | 亚洲视频999 | 亚洲欧美激情一区二区三区 | 精品久久久久久久久久久久久久 | 性欧美lx╳lx╳ | 91精品国产综合久久久密臀九色 | 欧美一区影院 | 波多野结衣精品 | 女仆裸体打屁屁羞羞免费 | 日日操夜夜摸 | 青青草久久伊人 | 黑人黄色片 | 在线观看欧美国产 | 中文在线免费视频 | 国产人妖网站 | 8x8x成人 | 天天干干干干干 | 国内精品人妻无码久久久影院蜜桃 | 日韩电影二区 | 国产51精品 | 美丽的小蜜桃2:美丽人生 | 四虎影院新网址 | 日本五十肥熟交尾 | 国产性生活片 | 一区二区三区不卡在线 | 国产精品无码久久久久高潮 | 日韩中文字幕在线视频 | 精品一区二区久久久久蜜桃 | www.国产高清 | 综合欧美亚洲 | 潘金莲性xxxxhd | 国产一级二级在线观看 | 91婷婷在线 | 91亚洲精品久久久久久久久久久久 | 日产精品一区二区 | 人妖ts福利视频一二三区 | 国产精品视频区 | 91精品国产亚洲 | 精品国产乱码久久久久久1区二区 | 少妇又白又嫩又色又粗 | 日本免费电影一区二区三区 | 亚洲欧美精品suv | 国产剧情av在线播放 | 欧日韩一区二区三区 | 一区二区三区国产精品视频 | 欧美日韩亚洲二区 | 女人下边被添全过视频 | 国产熟女高潮视频 | 污黄啪啪网 | 欧美v视频 | 双性受孕h堵精大肚生子 | 神马久久影院 | 日韩一区二区三区高清 | 国产免费一区二区三区视频 | 久久久久国产精品夜夜夜夜夜 | 国产精品27p | 狠狠爱五月婷婷 | 欧美日韩中文字幕在线视频 | 黄色欧美网站 | 国产区精品在线 | 视频一区亚洲 | 国产白丝在线观看 | 在线观看黄网址 | 日本啊v在线 | 欧美一区二区在线视频 | 日韩精品视频免费在线观看 | 成人免费一区二区三区在线观看 | 国产精品videos | 大香蕉毛片 | 日本男女激情视频 | 91久久综合亚洲鲁鲁五月天 | 九九精品视频在线观看 | 日日夜夜狠 |