Nanyang ACM to find the remainder

Source: Internet
Author: User
Remainder time limit: 1000 ms | Memory limit: 65535 KB Difficulty: 3 Description now give you a natural number n, its number is less than or equal to 1 million, now all you have to do is figure out the remainder after 10003. The first row has an integer m (1<=m<=8), which indicates that there are m groups of test data;
Then the M row has a natural number n per line. Output n divides the remainder after 10003 and takes one row for each output. Sample input
3
4
5
465456541
Sample output
4
5
6948
 
#include <iostream>
#include <stdio.h>

using namespace std;

Char a[1000005];

123% n = (((   (1%n  *  10%n + 2%n)%n*10%n)%n+3%n  )%n 
int main ()
{
	int n;< C18/>cin >> N;
	while (n--)
	{
		scanf ("%s", a);
		Long nc=0,rest;
		for (; a[nc]!= '; nc++ ')
		{
			a[nc]-= ' 0 ';
			if (NC = = 0)
			{
				rest = A[nc]% 10003
			}
			else
			{
				rest= (rest * + A[NC])%10003
			}
		cout << rest << 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.