1167: How Many Eggs Do I Have? 秦九韶定理
2010-11-17 13:53
330 查看
Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
---|---|---|---|---|---|
3s | 8192K | 2050 | 454 | Standard |
Assume you are needed to count a basket of eggs. Even though counting is very
easy but unfortunately you are forbidden to count them 1 by 1 instead of
counting them c by c, where c is greater than 1. For example, if you count them
3 by 3, then there will be 1 egg left in the basket, if you count them 5 by 5,
then there will be 3 eggs left in the basket and if you count them 7 by 7, then there
will be 1 egg left again in the basket. Your task is to determine how many eggs
there are originally in the basket.
Input Specification
The input consists of several test cases. The first line of each test casecontains an integer N(1<=N<=5), then follow N lines, each of which contains two integers
ci and bi(3<=ci<=49, 0<=bi<=ci-1, ci is a primary number). It means that you
count the eggs ci by ci and finally there are bi eggs left. N=0 marks the last
test case, which you should not process.
Output Specification
For each test case, you should print a line containing the minimal possiblenumber of eggs in the basket.
Sample Input
3 3 1 5 3 7 1 0
Sample Output
43 #include <stdio.h> #include <string.h> int c[10],b[10]; int l[10]; int main () { int N; while(scanf("%d",&N)==1&&N) { for(int i=0;i<N;i++) { scanf("%d%d",&c[i],&b[i]); l[i]=1; } for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(i!=j) l[i]*=c[j]; for(int i=0;i<N;i++) for(int j=1;;j++) if(l[i]*j%c[i]==1) { l[i]*=j; break; } int sum=0,tot=1; for(int i=0;i<N;i++) { sum+=l[i]*b[i]; tot*=c[i]; } printf("%d/n",sum%tot); } return 0; }
相关文章推荐
- joj 1167 How Many Eggs Do I Have?
- How many fix bug method do you have?
- How much GPU memory do iPhones and iPads have?
- How do I resolve `The following packages have unmet dependencies`
- Bubble Gum, Bubble Gum, in the dish, how many pieces do you wish?”
- [c++] How many bytes do pointers take up?
- How do I close a single buffer (out of many) in Vim?
- 日志 - How many times do you click per day?
- How many people have ipad II(数学)
- hdu-4724-How Long Do You Have to Draw-贪心
- HDU 4723 How Long Do You Have to Draw
- HDU 1796 How many integers can you find (容斥定理 + 二进制)
- When I use the Report Viewer ,I have the error,how should i do?
- How many people have ipad II(数学)
- HDU1796 How many integers can you find【容斥定理】
- HDU 4723 How Long Do You Have to Draw 解题报告
- zju 3557 How Many Sets II(Lucas 定理)
- PowerTip of the Day-How Much RAM Do You Have?
- hdu 4723 How Long Do You Have to Draw(贪心)
- How to do one-to-many video broadcast?