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

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 極限定律 閱讀(1906) 評論(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>
            亚洲激情自拍| 亚洲精品视频一区二区三区| 宅男噜噜噜66一区二区66| 欧美大色视频| 日韩亚洲成人av在线| 亚洲国产综合视频在线观看| 米奇777超碰欧美日韩亚洲| 伊人成人在线视频| 欧美国产精品一区| 欧美第一黄网免费网站| 一本一本久久a久久精品牛牛影视| 亚洲国产精品99久久久久久久久| 欧美插天视频在线播放| aa级大片欧美| 亚洲图片欧美一区| 国内不卡一区二区三区| 久久中文字幕一区| 在线亚洲高清视频| 亚洲视频高清| 中文精品在线| 午夜久久资源| 亚洲国产午夜| 亚洲图片欧洲图片日韩av| 国产日韩av一区二区| 美女精品网站| 欧美性久久久| 模特精品在线| 欧美午夜片在线观看| 欧美在线关看| 欧美xxx成人| 欧美一级视频免费在线观看| 久热国产精品视频| 亚洲在线网站| 麻豆成人综合网| 欧美在线视频一区二区| 久久综合伊人77777麻豆| 亚洲视频精品| 久久久久欧美精品| 午夜在线电影亚洲一区| 欧美不卡在线| 久久一区亚洲| 国产精品视频一| 亚洲激情不卡| 伊人久久av导航| 亚洲欧美精品| 亚洲精选91| 老鸭窝毛片一区二区三区| 欧美一乱一性一交一视频| 欧美伦理a级免费电影| 蜜桃av一区| 国产一区二区在线免费观看 | 91久久精品一区| 午夜精品视频在线观看一区二区| 亚洲乱码国产乱码精品精| 久久男人av资源网站| 久久福利资源站| 国产精品天美传媒入口| aaa亚洲精品一二三区| 91久久中文字幕| 久久婷婷久久| 欧美不卡在线| 在线精品在线| 久久久精品2019中文字幕神马| 亚洲最新视频在线播放| 欧美中文字幕久久| 亚洲欧美日韩精品在线| 欧美精品成人一区二区在线观看| 亚洲私人黄色宅男| 欧美日韩在线一二三| 欧美国产日韩精品| 伊人色综合久久天天| 欧美一级黄色网| 亚洲欧美影院| 国产精品激情| 宅男噜噜噜66一区二区| 亚洲自拍另类| 欧美日韩免费一区| 亚洲人成网站在线观看播放| 亚洲高清一二三区| 久久久久**毛片大全| 久久久噜噜噜久久久| 国产精品久久久久久久久久尿| 亚洲人成在线播放| 99在线观看免费视频精品观看| 久久影院亚洲| 美日韩免费视频| 悠悠资源网久久精品| 久久人人97超碰精品888| 免播放器亚洲一区| 亚洲国产高清视频| 免费一区视频| 亚洲精品国产拍免费91在线| 亚洲免费观看高清完整版在线观看熊| 久久久久这里只有精品| 欧美va亚洲va香蕉在线| 亚洲国产日韩欧美在线图片| 欧美好吊妞视频| 亚洲最新视频在线| 午夜精品久久久久久久| 国产精品视频一区二区三区| 亚洲欧美日韩成人高清在线一区| 久久精品国产第一区二区三区最新章节 | 亚洲一区欧美| 国产精品一级在线| av成人国产| 欧美一级欧美一级在线播放| 国产中文一区二区| 免费久久99精品国产自| 最新国产の精品合集bt伙计| 亚洲在线一区二区| 黄色亚洲大片免费在线观看| 久久综合中文色婷婷| 亚洲美女区一区| 亚洲免费视频网站| 亚洲国产精品一区制服丝袜| 欧美精品福利视频| 亚洲一区二区三区四区视频| 久久久最新网址| 9l国产精品久久久久麻豆| 国产精品综合久久久| 久久综合网hezyo| 亚洲欧洲久久| 女女同性女同一区二区三区91| 99视频精品全部免费在线| 国产日产欧产精品推荐色 | 午夜激情亚洲| 亚洲高清毛片| 久久不射网站| 亚洲国产你懂的| 国产亚洲人成a一在线v站| 欧美激情一区二区三区在线| 性一交一乱一区二区洋洋av| 亚洲大片av| 久久久久久久久岛国免费| 亚洲线精品一区二区三区八戒| 影音先锋久久| 精品动漫av| 国产乱码精品一区二区三| 欧美精品成人一区二区在线观看| 欧美与欧洲交xxxx免费观看| 99精品国产福利在线观看免费 | 亚洲国产精品成人久久综合一区| 欧美激情一区二区三区| 久久久久在线| 亚洲欧美一区二区三区久久 | 亚洲日本欧美天堂| 黑人巨大精品欧美一区二区小视频| 欧美日韩伦理在线免费| 牛人盗摄一区二区三区视频| 欧美一区二区三区精品电影| 一区二区欧美激情| 亚洲电影免费观看高清完整版在线| 午夜精品区一区二区三| 亚洲另类一区二区| 99精品欧美一区| 亚洲精品中文字幕在线| 亚洲福利视频网| 精品动漫3d一区二区三区免费| 国产欧美日韩视频| 国产精品久久久久久久久久久久久| 欧美国产视频在线| 欧美精品一区三区在线观看| 欧美激情视频一区二区三区在线播放| 狼人社综合社区| 麻豆精品91| 欧美1区2区3区| 欧美电影免费观看高清| 欧美大片免费久久精品三p| 免费日韩精品中文字幕视频在线| 久久免费精品视频| 欧美黑人多人双交| 欧美色大人视频| 国产精品日韩在线观看| 国产美女诱惑一区二区| 国产在线乱码一区二区三区| 在线看视频不卡| 亚洲日本激情| 亚洲午夜一二三区视频| 西西裸体人体做爰大胆久久久| 午夜精品一区二区三区四区 | 国产日韩视频| 激情小说另类小说亚洲欧美| 亚洲国产福利在线| 亚洲风情亚aⅴ在线发布| 亚洲国产欧美一区二区三区久久 | 欧美日韩国产小视频在线观看| 欧美人在线视频| 国产欧美日韩一区二区三区在线 | 久久天堂成人| 欧美精品在线一区| 欧美性感一类影片在线播放 | 亚洲视频1区2区| 久久久www| 欧美精品高清视频| 欧美日韩一区在线| 国产片一区二区| 亚洲精选视频在线| 久久激情视频久久| 亚洲黄色影片| 亚洲男人av电影|