青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Problem B : Always an Integer

Combinatorics is a branch of mathematics chiefly concerned with counting discrete objects. For instance, how many ways can you pick two people out of a crowd of n people? Into how many regions can you divide a circular disk by connecting n points on its boundary with one another? How many cubes are in a pyramid with square layers ranging from 1 × 1 to n × n cubes?


                   TFigure 1:T If we connect six points on the boundary of a circle, at most 31 regions are created.

Many questions like these have answers that can be reduced to simple polynomials in n. The answer to the first question above is n(n-1)/2, or (n^2-n)/2. The answer to the second is (n^4-6n^3+23n^2-18n+24)/24. The answer to the third is n(n+1)(2n+1)/6, or (2n^3+3n^2+n)/6. We write these polynomials in a standard form, as a polynomial with integer coefficients divided by a positive integer denominator. These polynomials are answers to questions that can have integer answers only. But since they have fractional coefficients, they look as if they could produce non-integer results! Of course, evaluating these particular polynomials on a positive integer always results in an integer. For other polynomials of similar form, this is not necessarily true. It can be hard to tell the two cases apart. So that, naturally, is your task.

Input
The input consists of multiple test cases, each on a separate line. Each test case is an expression in the form (P)/D, where P is a polynomial with integer coefficients and D is a positive integer denominator. P is a sum of terms of the form Cn^E, where the coefficient C and the exponent E satisfy the following conditions:
1. E is an integer satisfying 0 ≤ E ≤ 100. If E is 0, then Cn^E is expressed as C. If E is 1, then Cn^E is expressed as Cn, unless C is 1 or -1. In those instances, Cn^E is expressed as n or -n.
2. C is an integer. If C is 1 or -1 and E is not 0 or 1, then the Cn^E will appear as n^E or -n^E.
3. Only non-negative C values that are not part of the first term in the polynomial are preceded by +.
4. Exponents in consecutive terms are strictly decreasing.
5. C and D fit in a 32-bit signed integer.

 

See the sample input for details.
Input is terminated by a line containing a single period.

Output
For each test case, print the case number (starting with 1). Then print TAlways an integerT if the test casepolynomial evaluates to an integer for every positive integer n. Print TNot always an integerT otherwise. Print the output for separate test cases on separate lines. Your output should follow the same format as the sample output.

Sample Input
(n^2-n)/2
(2n^3+3n^2+n)/6
(-n^14-11n+1)/3
.

Output for the Sample Input
Case 1: Always an integer
Case 2: Always an integer
Case 3: Not always an integer

題目大概的意思是說:給定一個關于n的p次多項式,問該多項式是否為整值多項式。
根據定理:n次多項式f(n)是整值多項式當且僅當f(n)至少在n+1個連續的整數上都取整值。
只用將0-MAXPOW(取101)依次代入多項式的分子,并對分母d取模,判斷是否都為0即可。
至于為什么要取MAXPOW,而不是多項式f(n)的最大的次數max{pi}:為了使問題一般化,我們可以講所有的多項式都看成是MAXPOW次的,只不過當次數p>max{pi}時,其對應的系數ci全部為0,并不妨礙問題的解決。這樣一來,就不需要再額外求出f(n)的最大次數max{pi},使程序得到簡化。

399645  2009-04-23 07:44:07 Accepted 0.066 Minimum 19193  C++ 4119 - Always an integer
 1 #include <iostream>
 2 using namespace std;
 3 
 4 const int MAXPOW = 101;
 5 int c[MAXPOW],d;
 6 char ch;
 7 
 8 int calculate(long long n){
 9     int i;
10     long long ans=0;
11     for(i=MAXPOW;i>=0;i--)
12         ans=(ans*n+c[i])%d;
13     return (int)ans;
14 }
15 bool judge(){
16     int i;
17     for(i=0;i<=MAXPOW;i++)
18         if(calculate(i)) return false;
19     return true;
20 }
21 int main(){
22     int end,ca=1,sign,value,pow;
23     while(true){
24         ch=getchar();
25         if(ch=='.'break;
26         memset(c,0,sizeof(c));
27         while(true){
28             end=0,scanf(")%n",&end);
29             if(end) break;
30             scanf("+");
31             sign=0,value=1,scanf("-%n",&sign);
32             scanf("%d",&value);
33             if(sign) value=-value;
34             scanf("%nn%n^%n",&pow,&pow,&pow);
35             if(pow>1) scanf("%d",&pow);
36             c[pow]+=value;
37         }
38         scanf("/%d",&d);
39         getchar();
40         printf("Case %d: ",ca++);
41         puts(judge() ? "Always an integer" : "Not always an integer");
42     }
43     return 0;
44 }

posted on 2009-04-23 12:51 極限定律 閱讀(1880) 評論(0)  編輯 收藏 引用 所屬分類: ACM-ICPC World Final 2008題解

<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

導航

統計

常用鏈接

留言簿(10)

隨筆分類

隨筆檔案

友情鏈接

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久精品一区二区三区四区| 欧美在线视频a| 亚洲素人在线| 亚洲社区在线观看| 亚洲一区二区免费视频| 在线视频欧美一区| 亚洲图片欧洲图片av| 一本色道精品久久一区二区三区| 亚洲精品视频二区| 亚洲精选91| 亚洲一二三区精品| 午夜亚洲精品| 久久久久久久网站| 欧美成人精品三级在线观看| 91久久久亚洲精品| 亚洲激情成人| 亚洲一区二区成人在线观看| 欧美亚洲视频| 欧美岛国激情| 国产精品自拍在线| 亚洲国产精品一区二区www| 99香蕉国产精品偷在线观看| 午夜精品区一区二区三| 久久久人人人| 中日韩美女免费视频网站在线观看| 午夜精品久久久久久久白皮肤| 久久久噜噜噜久久狠狠50岁| 欧美日韩三级| 黄色在线一区| 亚洲一线二线三线久久久| 久久免费黄色| 最新国产成人av网站网址麻豆| 亚洲欧美日本日韩| 欧美日韩国产电影| 亚洲电影免费在线| 欧美在线一二三| 亚洲精品久久久久久久久久久久| 亚洲男人第一av网站| 欧美二区乱c少妇| 国产欧美日韩亚洲精品| 日韩午夜三级在线| 蜜臀91精品一区二区三区| 亚洲精品在线三区| 老司机精品久久| 国产日韩专区| 亚洲欧美三级伦理| 亚洲精品中文字| 蜜臀av性久久久久蜜臀aⅴ| 国产欧美精品一区二区三区介绍| 99伊人成综合| 亚洲激情电影在线| 久久影视三级福利片| 国产精品五区| 亚洲无限av看| 亚洲欧洲偷拍精品| 欧美成人精品在线观看| 亚洲制服av| 亚洲午夜极品| 亚洲激情在线| 久久九九电影| 黄色精品一区二区| 久久精品九九| 亚洲欧美另类在线| 国产日韩av在线播放| 午夜精品久久久久久久白皮肤| 亚洲精品一区二区三区樱花| 美乳少妇欧美精品| 一区二区三区在线视频播放| 久久福利资源站| 亚洲影院色无极综合| 国产精品久久久久久久久久久久久| 亚洲精品资源美女情侣酒店| 亚洲国产精品久久久久秋霞蜜臀| 蜜臀av在线播放一区二区三区 | 亚洲香蕉网站| 欧美视频四区| 午夜久久影院| 欧美在线二区| 亚洲第一精品夜夜躁人人爽| 欧美高清在线一区二区| 蜜臀久久99精品久久久久久9| 亚洲欧洲精品一区二区| 亚洲精品影院在线观看| 国产精自产拍久久久久久| 久久久91精品国产一区二区三区| 午夜一区二区三区在线观看| 影音先锋一区| 亚洲国产婷婷| 国产精品护士白丝一区av| 欧美在线视频一区二区| 久久嫩草精品久久久精品一| 最新国产の精品合集bt伙计| 亚洲理论在线观看| 国产精品免费看| 久久久久www| 欧美激情女人20p| 亚洲在线不卡| 久久久精品动漫| 一区二区三区日韩在线观看| 午夜精品一区二区三区在线播放 | 亚洲午夜精品国产| 欧美尤物巨大精品爽| 亚洲精品日韩久久| 欧美亚洲网站| 一本不卡影院| 久久精品国产v日韩v亚洲| 一区二区欧美视频| 久久se精品一区二区| 宅男精品导航| 免费久久99精品国产自在现线| 亚洲一级片在线观看| 久久国产精品第一页| 夜夜精品视频| 久久一区免费| 亚洲美女黄网| 欧美激情一区二区三区高清视频| 午夜精品理论片| 欧美国产日韩免费| 久色成人在线| 国产精品一区二区三区四区五区 | 亚洲永久免费av| 亚洲精品中文字幕有码专区| 久久久久国产精品厨房| 亚洲欧美一区二区精品久久久| 欧美国产先锋| 欧美成人首页| 韩国在线一区| 欧美一区二区三区四区高清 | 狠狠久久综合婷婷不卡| 在线视频中文亚洲| 亚洲精品一区二区网址 | 久久久久久婷| 欧美在线关看| 国产精品女主播| 中文在线一区| 一区二区三区视频在线| 免费永久网站黄欧美| 久久一区二区三区国产精品| 国产视频久久| 欧美一区2区视频在线观看 | 欧美日韩一二三区| 亚洲区欧美区| 日韩一二三区视频| 欧美激情精品久久久久久蜜臀| 欧美阿v一级看视频| 亚洲第一精品电影| 欧美中文字幕精品| 久久亚洲二区| 亚洲第一区在线| 欧美1级日本1级| 亚洲欧洲一区二区在线播放| 一本色道久久综合亚洲二区三区| 欧美人成免费网站| 99精品视频一区| 欧美一区视频| 狠狠操狠狠色综合网| 久久亚洲视频| 亚洲三级色网| 欧美一区二区三区精品| 国产亚洲精品美女| 久久综合色综合88| 亚洲精品日韩精品| 香蕉成人久久| 一区精品久久| 欧美日韩免费网站| 亚洲欧美国产毛片在线| 久久久综合视频| 亚洲精品一区二区三区在线观看 | 欧美日韩免费观看一区三区| 亚洲视频综合| 美女网站在线免费欧美精品| 一区二区三区视频在线播放| 在线一区二区三区做爰视频网站| 亚洲一区二区三区在线观看视频 | 激情综合激情| 欧美大香线蕉线伊人久久国产精品| 欧美日韩免费看| 在线观看亚洲视频啊啊啊啊| 国产亚洲精品aa午夜观看| 国产精品网站在线观看| 免费成人高清在线视频| 欧美日本韩国一区二区三区| 欧美精品性视频| 欧美美女操人视频| 夜夜嗨av一区二区三区四区| 亚洲欧美在线免费观看| 久久亚洲一区二区| 亚洲免费综合| 一区免费观看| 久久久久看片| 久久综合网色—综合色88| 亚洲国产精品久久久久婷婷884| 奶水喷射视频一区| 日韩午夜激情av| 国产视频一区二区三区在线观看| 蜜臀久久99精品久久久久久9| 欧美成人69av| 久久爱www.| 乱码第一页成人| 亚洲精品视频在线看|