思路题

来源:互联网 发布:mac梦幻西游启动器 编辑:程序博客网 时间:2024/04/30 14:58
 费马大定理:当n>2时,不定方程an+bn=cn没有正整数解。比如a3+b3=c3没有正整数解。为了活跃气氛,我们不妨来个搞笑版:把方程改成a3+b3=c3,这样就有解了,比如a=4, b=9, c=79时43+93=793。

输入两个整数x, y, 求满足x<=a,b,c<=y的整数解的个数。

Input

输入最多包含10组数据。每组数据包含两个整数x, y(1<=x,y<=108)。

Output

对于每组数据,输出解的个数。

Sample Input
1 101 20123 456789
Sample Output
Case 1: 0Case 2: 2Case 3: 16

因为1000^3=10的9次方,所以数字不超过1000

代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()

    int r=1;
    int x,y;
    while(~scanf("%d%d",&x,&y))
    {
        int ans=0;
        for(int a=x;a<=1000&&a<=y;a++)
        {
            for(int b=x;b<=1000&&b<=y;b++)
            {
                 int sum=a*a*a+b*b*b;
                if(sum/10>=x&&sum/10<=y&&sum%10==3)
                {
                    ans++;
                }
            }
        }
        printf("Case %d: %d\n",r++,ans);
    }
}

2

Digital clock use 4 digits to express time, each digit is described by 3*3 characters (including”|”,”_”and” “).now given the current time, please tell us how can it be expressed by the digital clock.


Input
There are several test cases.
Each case contains 4 integers in a line, separated by space.
Proceed to the end of file.
Output
For each test case, output the time expressed by the digital clock such as Sample Output.
Sample Input
1 2 5 62 3 4 2
Sample Output
    _  _  _   | _||_ |_   ||_  _||_| _  _     _  _| _||_| _||_  _|  ||_ 
Hint
The digits showed by the digital clock are as follows:   _  _     _  _  _  _  _  _  | _| _||_||_ |_   ||_||_|| | ||_  _|  | _||_|  ||_| _||_|
代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
string s1[15]={" _ ","   "," _ "," _ ","   "," _ "," _ "," _ "," _ "," _ "};
string s2[15]={"| |","  |"," _|"," _|","|_|","|_ ","|_ ","  |","|_|","|_|"};
string s3[15]={"|_|","  |","|_ "," _|","  |"," _|","|_|","  |","|_|"," _|"};
int main()
{
    int a[5];
    while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]))
    {
        cout<<s1[a[0]]<<s1[a[1]]<<s1[a[2]]<<s1[a[3]]<<endl;
        cout<<s2[a[0]]<<s2[a[1]]<<s2[a[2]]<<s2[a[3]]<<endl;
        cout<<s3[a[0]]<<s3[a[1]]<<s3[a[2]]<<s3[a[3]]<<endl;
    }
}



求n!的数的位数

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    int n;
    int p;

    while(~scanf("%d",&n))
    { double sum=0;
       for(int i=1;i<=n;i++)
        sum+=log10(double(i));
     p=int(sum);
    printf("%d\n",p+1);

    }
}


0 0
原创粉丝点击