牛客網練習賽18 A 【數論/整數劃分得到乘積最大/快速乘】
阿新 • • 發佈:2018-05-19
vector owb gcd algorithm CI -- ostream 最大的 sig
鏈接:https://www.nowcoder.com/acm/contest/110/A
來源:牛客網
題目描述
這題要你回答T個詢問,給你一個正整數S,若有若幹個正整數的和為S,則這若幹的數的乘積最大是多少?請輸出答案除以2000000000000000003(共有17 個零) 的余數。
舉例來說,當 S = 5 時,若幹個數的和為 5 的情形有以下 7 種(不考慮數字的順序的話):
- 1 + 1 + 1 + 1 + 1
- 1 + 1 + 1 + 2
- 1 + 1 + 3
- 1 + 2 + 2
- 1 + 4
- 2 + 3
- 5
他們的乘積依序為: - 1 * 1 * 1 * 1 * 1 = 1
- 1 * 1 * 1 * 2 = 2
- 1 * 1 * 3 = 3
- 1 * 2 * 2 = 4
- 1 * 4 = 4
- 2 * 3 = 6
- 5 = 5
其中乘積最大的是 2 * 3 = 6。
輸入描述:
輸入的第一行有一個正整數 T,代表該測試數據含有多少組詢問。
接下來有 T 行,每個詢問各占 1 行,包含 1 個正整數,代表該詢問的 S 值。
輸出描述:
對於每個詢問,請輸出答案除以 2000000000000000003(共有17個零) 的余數。
示例1
輸入
10
1
2
3
4
5
6
7
8
9
100
輸出
1
2
3
4
6
9
12
18
27
7412080755407364
備註:
1 ≤ T ≤ 100
1 ≤ S ≤ 2000
【知乎講解】
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algorithm> #include<vector> #include<map> #include<cctype> #include<stack> #include<sstream> #include<list> #include<assert.h> #include<bitset> #include<numeric> #define debug() puts("++++") #define gcd(a,b) __gcd(a,b) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define fi first #define se second #define pb push_back #define sqr(x) ((x)*(x)) #define ms(a,b) memset(a,b,sizeof(a)) #define sz size() #define be begin() #define pu push_up #define pd push_down #define cl clear() #define lowbit(x) -x&x #define all 1,n,1 #define mod 2000000000000000003 #define rep(i,n,x) for(int i=(x); i<(n); i++) #define in freopen("in.in","r",stdin) #define out freopen("out.out","w",stdout) using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> P; const int INF = 0x3f3f3f3f; const LL LNF = 1e18; const int MAXN = 1e3 + 5; const int maxm = 1e6 + 10; const double PI = acos(-1.0); const double eps = 1e-8; const int dx[] = {-1,1,0,0,1,1,-1,-1}; const int dy[] = {0,0,1,-1,1,-1,1,-1}; const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* long long Pow(long long a,long long b) { long long res=1; for(int i=1;i<=b;i++){ res*=a; res %= 2000000000000000003; } return res; } */ /* LL mul(LL a,LL b) { LL ans=0; while(b) { if(b&1) ans=(ans+a)%p; a=(a+a)%p; b=b>>1; } return ans; } LL Pow(LL a,LL b) { LL result=1; LL base=a%p; while(b) { if(b&1) result=mul(result,base)%p; base=mul(base,base)%p; b=b>>1; } return result; } */ int main() { long long ans, n; int t; cin>>t; while(t--){ ans = 1; cin >> n; while(n>4){ ans=ans*3%mod; n-=3; cout<<ans<<endl; } ans=ans*n%mod; cout<<ans<<endl; } return 0; }
牛客網練習賽18 A 【數論/整數劃分得到乘積最大/快速乘】