Number of bachelors

Source: Internet
Author: User
Small bachelor number of time limit: 1000 MS | memory limit: 65535 kb difficulty: 1
Description
Recently, topcoder's XD encountered a problem. If the last three digits of a number to the Power of Three are 111, such a number is called the number of small bachelors. He knows that the first batchy is 471,471, and the third power is 104487111. Now he wants to know the number of batchy (M <= 10000000000?
Input
There are multiple groups of test data. The first line is an integer N, indicating that there are N groups of test data. The next row contains an integer m.
Output
Output the maximum number of small bachelors.
Sample Input
1
1
Sample output
471

 

In my initial thought, this method was too complicated and the code was always unable to communicate with each other. In the end, I found that it should be time-out, but the submission was a compilation error.

#include<stdio.h>int main(){int n,i;__int64 m,t,j,k,s;scanf("%d",&n);for(i=0;i<n;i++){scanf("%I64d",&m);if(m==1)printf("471\n");else{for(j=2,k=1;j<=m;k++){t=471+k;s=t%1000;s=(s*s*s)%1000;if(s%1000==111){j++;}}    printf("%I64d\n",t);}}return 0;}



As long as the last three digits of this number are 471, this method is concise, but it still cannot be AC. The error prompt is a compilation error, which has been confusing.

#include<stdio.h>int main(){    int n;    __int64 s,m;    scanf("%d",&n);    while(n--){     scanf("%I64d",&m); s=(m-1)*1000+471;     printf("%I64d\n",s); }   return 0;}


Finally, I looked at the excellent code, only to find the problem, is the difference between long and _ int64 (http://blog.csdn.net/hongxdong/article/details/5559312)

#include<stdio.h> int main() {   long long a,b;        scanf("%lld",&a);         while(a--)     { scanf("%lld",&b);                printf("%lld\n",(b-1)*1000+471);     }     return 0; } 
Int, long, long range (for reference)

Unsigned int 0 ~ 4294967295
Int 2147483648 ~ 2147483647
Unsigned long 0 ~ 4294967295
Long 2147483648 ~ 2147483647
Maximum Value of long: 9223372036854775807
The minimum value of long:-9223372036854775808.
Maximum Value of unsigned long: 18446744073709551615

Maximum Value of _ int64: 9223372036854775807
_ Int64 minimum:-9223372036854775808
Maximum unsigned _ int64: 18446744073709551615


 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.