High precision divided by low fine (Angel's Oath)

Source: Internet
Author: User

Description
Tenshi was very fortunate to be chosen as the angel in charge of the key to wisdom. Before the official appointment, she must be sworn, like the other newly elected angels. The swearing-in ceremony was each angel's own mission, and their speeches were placed in a box of n round. These containers are numbered 1, 2, 3 ... in a clockwise direction., N-1, N. At first the Angels stood next to the treasure box numbered N. Each of them had a number on their hands, representing the box in which their own statement was written, starting from Box 1th, which was the first in a clockwise direction. For example: There are 7 boxes, so if the number on the Tenshi hand is 9, then the box for her speech is 2nd. Now the Angels begin to find the speeches according to their own figures, and first they can speak. Tenshi suddenly found, so she first took the oath: "I will lead you to open the door of noi ..." Tenshi after the oath, an angel came to the stage to take the oath. But there is an angel looking for a long time can not find her speech, the original her hands on the number m very large, she turned for a long time can not find the treasure box she wanted to find.
Please help this angel to find the number of the treasure box she is looking for.
Input
Each group of test data accounted for 2 rows, read into positive integers n and M, where N, M satisfies

2≤n≤108,2≤m≤101000
Output
Output the number of the Treasure box, one row

Sample Input
7
9
11
108

Sample Output
2
9

Ideas:
Because it is high-precision divided by low-precision (the problem to pay attention to the data range of the topic), so do not need to do high-precision division, directly according to the division formula can be done, but note that if the remainder is zero, then the label is the largest position.

 #include <cstdio> #include <iostream> #include <cstring> using namespace
Std
    int main () {int n;
    Char s[10009];
    int a[10009];
        while (cin>>n>>s) {memset (a,0,sizeof a);
       int Len=strlen (s);
        for (int i=0;i<len;i++) a[i]=s[i]-' 0 '; 
       int x=0;//store remainder for (int i=0;i<len;i++) x= (X*10+a[i])%n;//take-out if (x==0) cout<<n<<endl;
    else cout<<x<<endl;
} return 0; }

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.